0

I work in an environment where customer sends a HTTP Request to download a file which can sit on multiple servers in a cluster. There are around 5-10 servers in a cluster and the request to download the file can come to any server in the cluster. Technically I can know the IP of the Linux Server on the file is present. Now The approach that I am considering is to initiate a SFTP Connection to the known IP Address using JSch Library and fetch the file to the server where the HTTP Request first came. But the file is of 1-2 GB and I have to SFTP entire file to my primary server where the request came and from there send back the file in HTTP Response as application/octet-stream. Is there any alternative way where I do not have to copy entire file and then send back HTTP Response. Is there a way to use Lambda function to call the Target Server and to initiate download of that file from there directly to the client. Any answers and help might be really appreciated. This file download process is entirely in java. Can I use Java Lambdas to trigger file download from the target server directly to the caller.

3
  • Do you know which stacks are avaiable for this implementation in your project? try to look for libs that read files from sftp as a stream and an aplication api that return response as a stream too. eg. com.jcraft.jsch has a way to get files in sfpt as InputStream and springboot has a way to return response as StreamingResponseBody that does exactly you need. Commented Mar 1, 2024 at 12:58
  • In my setup, a Java REST Process runs on all servers in the cluster in parallel. Currently it does not implement spring boot but implements a light weight jersey container to support REST APIs. The Request can come to any of these Java Processes which are running in parallel on all servers in the cluster and the data file can be on any of these servers. So I can get the IP Address of the server which contains the file from the apache cassandra distributed DB connected to all of these servers. From there how I can proceed to download the file to the client without copying it to multiple servers Commented Mar 1, 2024 at 13:14
  • Try to read the content from sftp as a inputstream ( com.jcraft.jsch has a way to do it ) then return to reponse api as stream too ( see that stackoverflow.com/a/12012867/7505687 ) your client will request de dowload as stream, eg. xhr.responseType = "blob" ( it depends on how stacks are you using for download ) Commented Mar 1, 2024 at 15:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.