Upload File using Django Rest Framework

。_饼干妹妹 提交于 2019-12-03 07:43:57

File uploading in Django REST framework is the same with uploading files in multipart/form in django.

To test it you can use curl:

curl -X POST -H "Content-Type:multipart/form-data" -u {username}:{password} \
-F "{field_name}=@{filename};type=image/jpeg" http://{your api endpoint}

Other fields are just like normal form fields in Django.

Zhe answer is pretty well. Besides, you can add some parameters in order to see the response. Take this one for example:

curl -X PATCH --dump-header - -H "Content-Type:multipart/form-data" -u jorge:123456 -F "image=@/home/oscar/Pictures/dgnest/_MG_6445.JPG;type=image/jpeg" http://localhost:8000/api/project/3/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!