#Download a file with its given name
25 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @frosty rapids! Please use
/closeor theClose Postbutton 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.
What do you mean with downloading a file with a specific filename?
Do you want to let the user choose the location and name?
No I want to get the original file name as I would be downloading it from the browser, you know?
Do you ever plan to explain? How could anyone ever guess what it is you're speaking about?
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
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
I still didnt code it yet
You can get the Content-Disposition response header
and extract the filename from there
Okay, I'll look into the headers real quick
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:
Servers don't have to provide the Content-Disposition field
In this case, the file name is inferred from the URL
Hm I see, let me try another url
preferably one where the name in the URL is different from the name you get when downloading it in the browser
Unfortunately the site where I will be downloading the files from is not creating that header :/
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.