【发布时间】:2015-07-07 00:59:35
【问题描述】:
我正在尝试使用 POSTMAN 上传图片。我成功使用了表单数据,但没有以原始 JSON 格式传递数据。
通过 POSTMAN 中的表单数据请求:
通过 curl 请求:
curl -X POST -H "Content-Type:multipart/form-data" -F "profile_image=@/home/shivani/Pictures/Wallpapers/8018.jpg" http://127.0.0.1:8000/api/users/1/image/
{"message":"Image Uploaded successfully.","profile_image":"http://res.cloudinary.com/aubergine-solutions/image/upload/v1430204993/w0oxhv6beaxd14twrxmi.jpg"}~
当我以原始格式发送请求时:
虽然我在 Django 设置中添加了 MultiPartParser,但出现以下错误:
谁能帮忙解决这个问题?
【问题讨论】:
-
好吧,只是为了指定是否有人遇到这个问题,如果您想使用 json 上传图像,则需要附加图像的 base64 字符串,如
"profile_image": { "name": "72397.jpg", "content_type":"image/jpg", "file":"base64string"}或者任何一种方式都是“form-data " -
我现在也有同样的问题。我需要用图像传递基本数据。你能给我代码吗,你是如何用原始数据传递图像的。
标签: django request image-upload postman