Download png from link, Cannot get download of png to work with a link |
Download png from link, Cannot get download of png to work with a link |
Urgaan |
May 16 2018, 06:04 AM
Post
#1
|
Group: Members Posts: 3 Joined: 16-May 18 Member No.: 26,646 |
Hi all,
I've been wanting to get an export function to work on my site, which almost works perfectly, it just does not download automatically. Currently it generates this: <a target="_blank" download="MediumRandomNewick_treemap_outer.png" href="blob:http://localhost:8080/c02ebb93-19b9-43fa-872d-b32fc02dc56f">Export</a> But this is not clickable and also does not force the download, can anyone tell me how I would go about force downloading? Preferably with JavaScript. |
Christian J |
May 17 2018, 04:34 PM
Post
#2
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
Seems the DOWNLOAD attribute at least works with data URIs like this:
CODE <a download="test.png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==">Example</a> (the above should generate an image file depicting a red dot). |
pandy |
May 18 2018, 12:53 AM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Duh. I didn't notice the 'data:image/png;base64' bit. Well, then I'm stumped too.
|
pandy |
May 18 2018, 08:04 AM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Duh. I didn't notice the 'data:image/png;base64' bit. Well, then I'm stumped too. ... because it was never there. I thought you quoted from the OP's post. I googled some and if I understand it right, the blob protocol can't be used like this at all, hardcoded. It can only be used programmatically. If that is true only the URL in the download attribute is used. An image can't be an SVG and a PNG at the same time. Does it open normally in an image editor? I know for example Irfan View opens images with the wrong extension but warns about it an offers to rename them properly. Most standard image editors or viewers don't handle SVG at all. |
Christian J |
May 18 2018, 08:21 AM
Post
#5
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
I thought you quoted from the OP's post. No it's from Wikipedia. QUOTE only the URL in the download attribute is used. Note that the attribute value only suggests a filename, it's not a actual URL. QUOTE Does it open normally in an image editor? I know for example Irfan View opens images with the wrong extension but warns about it an offers to rename them properly. Most standard image editors or viewers don't handle SVG at all. That doesn't affect how the browser handles the download though, you can name the download file "foo.bar" and it will still download. But if you want the downloaded file to be usable (once downloaded), you must of course use a working file extension (at least in Windows). |
Lo-Fi Version | Time is now: 26th April 2024 - 02:32 PM |