Momentum logo
Team 10 Classroom

๐Ÿป File Upload with Django and DRF ๐Ÿป

Posted on Dec 21st, 2021

๐Ÿ—“๏ธ Todayโ€™s Topics

  • Project Progress
  • File Uploads

๐Ÿ”– Resources

File uploads

POST with upload using Insomnia

  • Choose binary file attachment from the JSON menu (where you normally put the body of a request)
  • Headers (this example assumes an image file in jpeg format, named profile-photo .jpg):

    Content-Type: image/jpeg
    Content-Disposition: attachment; filename=profile-photo.jpg
    

For more information on the values for Content-Type:

CORS for file upload

Assuming you are using django-cors-headers, youโ€™ll need to add the following to settings.py:


from corsheaders.defaults import default_headers

CORS_ALLOW_HEADERS = list(default_headers) + [
    'content-disposition',
]

๐Ÿ“– Read | ๐Ÿ“บ Watch | ๐ŸŽง Listen

Back to home