How to configure api (structure) to download a file from the server


So I am making a program in java that would download a file from a server. I have a server set up with bottle web framework.

Now I'm not sure how exactly I should transfer the data from the server to the client side.

Here are the two ideas I've thought of.

  1. Make the file I need to download as a static file on the server and just use the java to download it.

  2. Send a post request to the server which replies with part of the data and I have to iterate through it until I have the full file.

Number 1 would be the easiest but I guess anyone could access it that way so it might not be the best idea.

Do you guys have any suggestion on how I should structure it?

Assuming you are using Servlets or Servlet based frameworks.

Write the file content to the response and set the Content-Disposition: attachment; filename=yourfilename with the file name. If needed you may need to set the Content-Transfer-Encoding: binary header as well.