Upload File using Django Rest Framework

后端 未结 2 997
夕颜
夕颜 2021-02-09 06:07

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-framew

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-09 06:22

    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.

提交回复
热议问题