๐ป File Upload with Django and DRF ๐ป
Posted on Dec 21st, 2021
๐๏ธ Todayโs Topics
- Project Progress
- File Uploads
๐ Resources
File uploads
- Django Docs: ImageField
- Django Docs: FileField
- Pillow: Python Imaging Library
django-imagekit
-> If you want to resize images when they are uploaded, or do any kind of image processing, you will need this. Donโt add it unless you know you need it.
- How to Setup Amazon S3
django-storages
- DRF
FileUploadParser
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
- ๐ File Upload with DRF
- ๐ง + ๐ Success with Static Files
- ๐ What is Amazon S3? -> Skim this โ this is Amazonโs documentation and it gets really in-depth.
- ๐บ Introduction to S3 -> Also from Amazon