Momentum logo
Team 12 Classroom

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

Posted on Jun 7th, 2022

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

  • Project Progress
  • File Uploads

๐Ÿ”– Resources

File uploads

A request with a file attachment using Insomnia

  • Select the right HTTP method for your endpoint.
  • Choose binary file attachment from the JSON menu (where you normally put the body of a request)
  • Set headers on the Headers tab (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:

# in settings.py

from corsheaders.defaults import default_headers

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

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

Back to home