简体   繁体   English

RESTful Web服务使用JSON上载/下载大数据

[英]RESTful Web Service Upload/Download Large Data With JSON

What is the best practice if you are implementing web services that will send and receive large files to/from clients. 如果要实现向客户端发送大型文件和从客户端接收大型文件的Web服务,最佳做法是什么。 Normally we are sending JSON objects, but it could be problematic if we include large data payload inside of the JSON objects. 通常我们发送JSON对象,但如果我们在JSON对象中包含大数据有效负载,则可能会出现问题。 We need to provide JSON data as well as a payload, anyone have experience with something similar? 我们需要提供JSON数据以及有效载荷,任何人都有类似的经验吗?

You could embed links to the raw data in your JSON responses. 您可以在JSON响应中嵌入指向原始数据的链接。 For example: 例如:

{
   title: 'A Really Big File',
   date: '2011-11-11',
   file: 'http://example.com/really_big_file.xls'
}

That way you can allow clients to decide whether or not they want to dereference the big file or not. 这样,您可以允许客户决定是否要取消引用大文件。

Base64 is a very inefficient way of doing this, but universal. Base64是一种非常低效的方法,但却是通用的。 You could send your files using HTTP Post-request with special parameter "multipart/form-data". 您可以使用带有特殊参数“multipart / form-data”的HTTP Post-request发送文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM