Uploading images/videos directly to the Django server or letting media server handle it
Just straight to the point, here's my django model:
class Product(models.Model):
name = # charfield
unit_price = # decimal field
video = # FileField or whatever, just a video related this product
class ProductImage(models.Model):
product = models.ForeignKey(Product, ...)
And I have relevant serializers. My question is:
Before as a beginner, my first natural process would be to send everything including the media in one payload as a multipart form
Now my understanding is, I shouldn't let the HTTP server handle media uploads, it's for HTTP req/res.
So the solution is, let a third-party media service handle this. So the flow becomes:
- Create the product -> returns
201 Created-> upload the video -> video upload successful -> PATCH video url
or,
- Upload the video first, then create the product attaching the
urlto thePOSTbody.
- Create the product -> returns
Both of them have this one issue, after the video is created, but the PATCH [1] or POST [2] fails, then the product and video remains unlinked.
Also, the frontend has to do all these extra steps they complain about.
Another way, let the backend handle this, but then again how do I divert the pressure away from the HTTP server.
How do you guys handle this actually?
Just straight to the point ... that makes it not straight to the point ... please don't write unnecessary text