使用Django Rest Framework上传文件 [英] Upload File using Django Rest Framework
本文介绍了使用Django Rest Framework上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过以下页面:
http://www.django-rest- framework.org/api-guide/parsers/#fileuploadparser
解决方案
Django REST框架中的文件上传是一样的在django中以multipart / form格式上传文件。
要测试,可以使用curl:
curl -X POST -HContent-Type:multipart / form-data-u {username}:{password} \
-F{field_name} = @ {filename} ; type = image / jpeghttp:// {your api endpoint}
其他字段就像Django中的正常表单字段。
I am new to django. Can anybody help me... How can I upload a file using the Rest Framework API ?
I have tried following this page:
http://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser
解决方案
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.
这篇关于使用Django Rest Framework上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文