0

In my web application I have a link which, when clicked, invokes an external web service to retrieve a download URL for a file.

I need to send back to client the file which is beyond this URL, instead of the download URL retrieved from the web service. 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. Is there a similar way to do this in Java 8?

Ricky Sixx
  • 581
  • 1
  • 10
  • 25
  • Would be useful to see your controller method and the way `request`, `response` is handled. Otherwise you could use `URLConnection` read line by line and send to response output stream, eg https://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html – Ivar May 25 '20 at 12:49
  • @Aivaras unfortunately I use a framework which does not expose directly the servlet request/response. I've tried to add some details to my question. – Ricky Sixx May 25 '20 at 13:07

1 Answers1

0

If you doesn't even want to handle that file you should answer the request with a redirect (eg HTTP 301 or 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.

jsc57x
  • 71
  • 6
  • I did not think about redirection, which is exactly I need in my case. I've tried to perform a redirect to the URL retrieved from the web service and it works, thank you very much! – Ricky Sixx May 25 '20 at 13:12