我正在尝试使用 POSTMAN 上传图像。我成功地使用了表单数据,但没有以原始 JSON 格式传递数据。
request through form-data in POSTMAN:
request through 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,但我收到以下错误:
有人可以帮助解决这个问题吗?
最佳答案
当我使用图像上传时,我使用 base64 对图像进行编码,并将该编码字符串作为 json 字符串传递。在后端,我们可以解码字符串并制作图像。试试这个,我认为它有效。
关于django - 如何在 POSTMAN 中使用 raw 上传图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29914974/