【问题标题】:How to upload image using raw in POSTMAN?如何在 POSTMAN 中使用 raw 上传图像?
【发布时间】: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


【解决方案1】:

当我使用图像上传时,我使用 base64 对图像进行编码,并且该编码字符串作为 json 字符串传递。在后端我们可以解码字符串并制作图像。试试这个,我认为它有效。

【讨论】:

    猜你喜欢
    • 2017-11-17
    • 2017-12-09
    • 2019-03-27
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2017-06-07
    • 2021-03-31
    • 1970-01-01
    相关资源
    最近更新 更多