邮递员使用Raw在API上载文件 [英] Postman upload file on API using raw

查看:105
本文介绍了邮递员使用Raw在API上载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用原始模式在邮递员上上传文件.

How do you upload a file on postman using raw mode.

我使用了这样的json条目:

I used a json entry like this:

{
    "inp_doc_uid": "750761691595cf3398da311004881705",
    "tas_uid": "71415152859433e07c33b11085554015",
    "app_doc_comment":"test upload",
    "form":"@/User/images.jpg"
}

问题是php中的@已被弃用,现在建议使用curlFile,如何以json格式进行操作?

the problem was the @ in php was deprecated and now recommended to use curlFile, how to do it in a json form?

谢谢.

推荐答案

由于您将图像作为JSON的一部分发送,因此需要对其进行编码.Base64编码是一个不错的选择.在服务器端,您也需要对其进行解码.

Since you are sending the image as part of the JSON, you would need to encode it. Base64 encoding is a good choice. On the server side, you will need to decode it as well.

请参见如何将图像转换为base64编码?:

$imagedata = file_get_contents("/path/to/image.jpg");
$base64 = base64_encode($imagedata);

一旦有了数据,就可以将其添加到JSON:

Once you have the data, you can add it to the JSON:

{
    "inp_doc_uid": "750761691595cf3398da311004881705",
    "tas_uid": "71415152859433e07c33b11085554015",
    "app_doc_comment":"test upload",
    "form":"TWFuIGlzIGRpc3R..."
}

另请参见 Base64参考

这篇关于邮递员使用Raw在API上载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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