[英]java - send a file to client by file URL without download on the server
In my web application I have a link which, when clicked, invokes an external web service to retrieve a download URL for a file.在我的 web 应用程序中,我有一个链接,单击该链接会调用外部 web 服务来检索文件的下载 URL。
I need to send back to client the file which is beyond this URL, instead of the download URL retrieved from the web service.我需要将超出此 URL 的文件发送回客户端,而不是从 web 服务检索的下载 URL。 If possible, I would also like to do it without having to download the file on my server beforehand.
如果可能的话,我也想这样做,而不必事先在我的服务器上下载文件。
I've found this question about a similar task, but which used PHP with the readfile()
function.我发现了这个关于类似任务的问题,但它使用了 PHP 和
readfile()
function。 Is there a similar way to do this in Java 8?在 Java 8 中是否有类似的方法可以做到这一点?
If you doesn't even want to handle that file you should answer the request with a redirect (eg HTTP 301 or 302).如果您甚至不想处理该文件,您应该使用重定向来回答请求(例如 HTTP 301 或 302)。 If you want to handle the file you should read the file in a byte buffer and send it to the client which would make the transfer slower.
如果要处理文件,则应在字节缓冲区中读取文件并将其发送到客户端,这会使传输速度变慢。 Without seeing your implementation so far, this is my best suggest.
到目前为止还没有看到你的实现,这是我最好的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.