[英]What is the correct way of returning a file in a Rest webservice request?
I need to return a file in my webservice. 我需要在Web服务中返回文件。 I am bit in doubt of what is the best/correct/execpted way.
我对什么是最佳/正确/执行方式感到怀疑。 (I am using JSON).
(我正在使用JSON)。
I can: 我可以:
All three are valid, depending on the client's needs, so why not make it the client's choice? 这三个都是有效的,具体取决于客户的需求,那么为什么不让它成为客户的选择呢?
Let's say it's an image/jpeg
file: 假设这是一个
image/jpeg
文件:
If the client sent the Accept: image/jpeg
header, you return the file as a normal download. 如果客户端发送了
Accept: image/jpeg
标头,则将文件作为正常下载返回。
If the client sent the Accept: image/jpeg
header and the Accept-Encoding: base64
, you return it as a normal download, Base64 encoded. 如果客户端发送了
Accept: image/jpeg
标头和Accept-Encoding: base64
,则将其作为常规下载(Base64编码)返回。
If the client sends the Accept: text/uri-list
header, you return a plain text response with the URI for the image stored somewhere else. 如果客户端发送
Accept: text/uri-list
标头,则返回纯文本响应,其中包含存储在其他位置的图像的URI。
There are no standard mimetypes to return base64 or links inside json, but you can use some standard of your own and create a vnd mimetype, as long as you document it. 没有标准的mimetypes返回json中的base64或链接,但是您可以使用自己的一些标准并创建vnd mimetype,只要您对其进行了说明即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.