是否可以在POST Json中附加文件? [英] Is it possible to attach file in POST Json?

查看:118
本文介绍了是否可以在POST Json中附加文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆JSON(序列化对象)格式的数据. 我通过标题为Content-Type: application/jsonPOST方法将此数据发送到服务器.

I have a heap of data in format JSON(Serialized object). I send this data to server by POST method with header: Content-Type: application/json.

是否可以将文件附加到正文请求并立即发送.还是JSON数据建议仅发送文本数据?

Is it possible to attach file to body request and send at once. Or JSON data sugggests sending only text data?

推荐答案

尝试将json对象中的文件作为base64字符串发送:

Try to send the file inside the json object as a base64 string:

{
"file":"dGhpcyBpcyBhIGZpbGUgc2FtcGxl..." 
}

以后,您可以使用类似以下的方式打开文件:

Later you can open the file with something like:

document.location = 'data:application/pdf;base64,' + file

这篇关于是否可以在POST Json中附加文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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