如何使用邮递员测试图片上传API?

时间:2019-08-24 14:57:49

标签: postman apiclient

我有一个图像上传API,可以从android调用它,并且可以正常工作。现在,我想使用Postman测试相同的API。

请有人指导我在Postman上测试此API。我需要在Postman中设置哪些参数才能测试此API。

我已经尝试使用post man中的以下参数测试此API,但到目前为止仍无法成功。我尝试将图片附加到邮递员参数中,然后将图片转换为二进制文件,然后将该二进制文件添加到邮递员参数中,但API给出的响应失败。

--16cbe71399a
Content-Disposition: form-data; name="binaryFile"; filename="ec6152a8a12b4782b1c4bcc95cc98eeb"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
binaryFile:{local path of image}
--16cbe71399a--

有效的android代码如下:

API:http://testing/api/editImage/

标题:

("Content-Type", "multipart/form-data; boundary=" + boundary);<br>
("Authorization", "bearer "+preference.getFileAPIAuthenticationToken())<br>

身体:

writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + ugid + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
writer.append(CRLF);
// file write in binary
writer.append(CRLF);
writer.append("--" + boundary+ "--").append(CRLF);

1 个答案:

答案 0 :(得分:1)

要通过邮递员测试图片上传api:

  1. 打开邮递员应用程序,然后输入网址。
  2. 单击 POST 作为http请求的类型。
  3. 现在在“身体”标签中:

    • 从下拉菜单中单击表单数据选项。

    • 添加名称键并输入您的活动名称(我在上传图片时称呼我的图片)。

    • 在提供键名而不是文本的过程中可见的下拉菜单中的“选择文件”选项。
    • Choose Files标签将添加到相邻的值部分,您可以在其中选择文件。
    • 单击Send按钮并通过调试器转到您的应用程序以查看输出。

这是屏幕截图:

enter image description here

相关问题