通过 Postman 发送带有图像的 POST json 对象

Posted

技术标签:

【中文标题】通过 Postman 发送带有图像的 POST json 对象【英文标题】:Sending a POST json object with image through Postman 【发布时间】:2018-10-15 08:34:30 【问题描述】:

我目前正在通过 Postman 的原始类别发送类似的内容。这工作正常,但我无法附上图片


"user" :       
             "first_name": "employeeA",   
             "last_name": "smith",
             "username": "employeeA",
             "employer_image" :  --->Insert image here
             ,     
"employee_zip" : 12345
 

但是我不知道如何附加图像文件。我读了here,我可以改为使用表单数据类别并发送图像。所以我做了这样的事情

这不起作用我有什么方法可以选择一个文件然后使用原始 json 指向该文件?

【问题讨论】:

【参考方案1】:

您是否尝试过使用 Base64 编码的字符串? 最终的 JSON 对象看起来像这样......


    "user" :    
        "first_name" : "employeeA",   
        "last_name"  : "smith",
        "username"   : "employeeA",
        "employer_image" : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="
    ,
   "employee_zip"   : 12345       
 

您可以在Mozilla Developer Website 中找到 Base64 编码器的详细信息,在 Github 中可以找到许多实现

出于测试目的,您可以先尝试online converter,正如@MistyD 在 cmets 中所建议的那样。

【讨论】:

看起来这可能对我有用。让我看看能不能找到将图像编码为 base64 的东西 我现在要试试这个

以上是关于通过 Postman 发送带有图像的 POST json 对象的主要内容,如果未能解决你的问题,请参考以下文章

postman怎么发送json参数

使用 Postman 通过原始 JSON 发送 POST 数据

使用postman发送post数据时遇到的问题

使用 Retrofit 发送带有参数的 Post 请求

“使用 POSTMAN 发布图像数据”

通过 Axios 发送一个 post 请求是在 Spring-Boot 后端生成一个空的 RequestBody。在 Postman 中工作,但不能通过 Axios 发布请求