RESTful Web Service Upload/Download Large Data With JSON

与世无争的帅哥 提交于 2019-12-24 22:09:47

问题


What is the best practice if you are implementing web services that will send and receive large files to/from clients. Normally we are sending JSON objects, but it could be problematic if we include large data payload inside of the JSON objects. We need to provide JSON data as well as a payload, anyone have experience with something similar?


回答1:


You could embed links to the raw data in your JSON responses. 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.




回答2:


Base64 is a very inefficient way of doing this, but universal. You could send your files using HTTP Post-request with special parameter "multipart/form-data".



来源:https://stackoverflow.com/questions/8128361/restful-web-service-upload-download-large-data-with-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!