Download a file with its given name
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?
18 Replies
⌛
This post has been reserved for your question.
Hey @TomasGnG 😴! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
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 thereOkay, I'll look into the headers real quick
MDN Web Docs
Content-Disposition - HTTP | MDN
In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.
Is this correct?
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 URLHm 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.
Post Closed
This post has been closed by <@386870647894048768>.