I'm using window.location
to download my image. It isn't in HTML
because I generate the image on the server and then send it back down so it looks like :
window.location = data.url;
I've seen a few other questions but they suggest the download
attr which I don't have because there's no HTML
.
Is there a way I can change the file name?
The only thing you can do on the front-end side is to change your code to HTML <a>
element with download
attribute:
<a href="my_file.pdf" download="very_important_report.pdf">Download</a>
When user clicks this link, the browser forces download and saves the file with given filename. You can read more about it in this post. It's quite a new feature so check the browser support.
If you can modify the server-side code then you should use content-disposition
header as defined in RFC 2183.
content-disposition: attachment; filename=very_important_report.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With