使用 Postman 通过 HTTP POST 上传图像 [英] Upload an image through HTTP POST with Postman

查看:32
本文介绍了使用 Postman 通过 HTTP POST 上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过 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:

邮递员客户端"端:

  1. 选择POST请求
  2. 选择 HEADER Content-Type 值为 multipart/form-data
  3. 在 Body 选项卡中选择 form-data 引入 key = image_test,从 Text 更改为 File并搜索图片,例如:photo.png
  4. 发送 POST 请求.
  1. Select POST request
  2. Select HEADER Content-Type with value multipart/form-data
  3. 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
  4. 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

这篇关于使用 Postman 通过 HTTP POST 上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆