Here is a DOM like this.
<img id="this-is-the-image" src="http://192.168.1.100/Image_tmp/2016-06/d4eb8d">
I need to click a button, run a JS, and download this image file.
I have finished the button and the download script.
Some code:
```
function downloadFile(fileName, url) {
var aLink = document.createElement('a');
var blob = new Blob([url]);
var evt = document.createEvent("HTMLEvents");
getImageType(blob);
evt.initEvent("click", false, false);
aLink.download = fileName;
aLink.href = URL.createObjectURL(blob);
aLink.dispatchEvent(evt);
}
```
I have a problem. I can only get the src "http://192.168.1.100/Image_tmp/2016-06/d4eb8d"
or the name d4eb8d
, but actually the image is .png
or .jpg
.
The brower can view it, but after I save
it to my computer, the file name turn to be d4eb8d
, not d4eb8d.png
or d4eb8d.jgp
.
How can I get the real type of the image so that I can specify the download_name?