使用 Postman 通过 HTTP POST 上传图像图像、上传、Postman、HTTP

2023-09-07 11:04:22 作者:天生励志难自弃

我一直在尝试通过 Postman 将图像发送到一个简单的 PHP 脚本,该脚本应该显示发送的图像.我遵循的步骤是:

I've been trying for a while to send an image via Postman to a simple PHP script that should display the sent image. The steps I followed were:

邮递员客户端"端:

选择POST请求选择 HEADER Content-Type 值为 multipart/form-data在 Body 选项卡中选择 form-data 引入 key = image_test,从 Text 更改为 File并搜索图片,例如:photo.png发送 POST 请求. Select POST request Select HEADER Content-Type with value multipart/form-data In the Body tab select form-data introduce the key = image_test, change from Text to File and search for a image, ex: photo.png Send POST request.

在 PHP 脚本中,我只有:echo '<img src="data:multipart/form-data,' . $_POST['image_test'] .'"/>';

In the PHP script I just have: echo '<img src="data:multipart/form-data,' . $_POST['image_test'] .'"/>';

尽管使用 print_r($_POST) 我可以看到编码图像,但此解决方案对我不起作用.这可能是主机(https://ide.c9.io)或邮递员的问题吗?我对 Postman 和 base64 图像进行了一些其他测试,但 Postman 的 Display 选项卡无法显示解码后的图像;唯一的方法是通过浏览器访问.

This solution isn't working for me although with print_r($_POST) I'm able to see the encoded image. Could this be a problem of the host (https://ide.c9.io) or Postman? I made some other tests with Postman and base64 images and the Display tab of Postman wasn't able to display the decoded images; the only way was to access through the browser.

推荐答案

一些代码可以帮助你理解你想要做什么.您可以尝试以 base64 编码将图像发送回客户端.有关示例,请参阅如何将图像转换为 base64 编码?

Some code would help to understand what you are trying to do. You could try to send the image back to the client in base64 encoding. See How to convert an image to base64 encoding? for an example