#Download a file with its given name

25 messages · Page 1 of 1 (latest)

frosty rapids
#

Normally if you want to download a file through your browser, the browser asks you for the destination path and the name of the file is already given.

Now I want to download a file with that specific filename. How can I do that?

hardy ivyBOT
#

This post has been reserved for your question.

Hey @frosty rapids! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

wicked sandal
#

What do you mean with downloading a file with a specific filename?

#

Do you want to let the user choose the location and name?

frosty rapids
#

No I want to get the original file name as I would be downloading it from the browser, you know?

reef saddle
#

Do you ever plan to explain? How could anyone ever guess what it is you're speaking about?

frosty rapids
#

Did you ever download a file with your browser?
Then you should've seen that the name of the file is always given. But when I download a file with Java I need to use a filename which I want to avoid

wicked sandal
#

Are you downloading a file from a Java application using the URL?

#

If so, can you show the code? What are you using for downloading the file?

#

I think the filename is in an HTTP header

frosty rapids
#

I still didnt code it yet

wicked sandal
#

You can get the Content-Disposition response header

#

and extract the filename from there

frosty rapids
#

Okay, I'll look into the headers real quick

wicked sandal
frosty rapids
#

Is this correct?

HttpURLConnection conn = (HttpURLConnection) new URI("https://tomasgng.dev/plugins/dynamicseasons/download/DynamicSeasons-2.5.0.jar").toURL().openConnection();
conn.connect();

Because I am only getting these headers:

wicked sandal
#

In this case, the file name is inferred from the URL

frosty rapids
#

Hm I see, let me try another url

wicked sandal
#

preferably one where the name in the URL is different from the name you get when downloading it in the browser

frosty rapids
#

Unfortunately the site where I will be downloading the files from is not creating that header :/

#

Still thank you for your help

hardy ivyBOT
# frosty rapids Still thank you for your help

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.