download image decoded from data uri - chrome extension

Viewed 69

I have a data uri image and after decoding it and disply into an <img> tag I want to give to the user the ability to download it. How I can achive this in a chrome extension? what kind of url I need to pass to the chrome.downloads.download api method?

1 Answers

This function should work, and I think that as long as you can see the image it should work withe existing url

 function downloadImage(url, outputFileName){
      var a = document.createElement('a');
      a.href = url;
      a.download = outputFileName;
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a); 
    }
Related