I want to download a picture as soon as I click on it. The picture itself is SVG but I have an URL for a PNG image. I checked and the content disposition is attachment, and yes when I copy the URL directly a download immediately starts.
I am using Bootstrap 4
The function
function downloadPNGImage(linkElement) {
var myDiv = document.getElementById('download-area');
var myImage = myDiv.children[0];
let downloadLink = myImage.src + "&format=png";
linkElement.setAttribute('download', downloadLink);
linkElement.href = downloadLink;
}
And the image itself is:
<div class="col-lg-5 order-first order-md-last img-fluid" id="download-area">
<img src="https://bananomonkeys.herokuapp.com/image?address=ban_1ttyqinz739g88tteqzyg3hwahg9oxbks8amsywqmim7j4afih7n9d1ssqjf&bg=t"
class="loaded" id="generated-monKey" alt="" href="#" onclick="downloadPNGImage(this)" download>
</div>
So when I add "&format=png" this URL is no longer an inline SVG, it is an attached PNG that I would like to download, but for some reason, it doesn't work.