Incorrect mime type HTML5 anchor
Opened this issue · 1 comments
acourdavault commented
Hello,
When using this library to download a FileResponse from Django returning a PDF file content I realized that the MIMI type was ignored.
download(myBlob, "labels.pdf", 'application/pdf');
I realized that in the paragraph L101-116 the attribute 'type' was not set.
1 line change fixes this
function saver(url, winMode){
if ('download' in anchor) { //html5 A[download]
anchor.href = url;
anchor.setAttribute("download", fileName);
//MODIFICATION START
anchor.setAttribute("type", mimeType);
//MODIFICATION END
anchor.className = "download-js-link";
anchor.innerHTML = "downloading...";
anchor.style.display = "none";
document.body.appendChild(anchor);
setTimeout(function() {
anchor.click();
document.body.removeChild(anchor);
if(winMode===true){setTimeout(function(){ self.URL.revokeObjectURL(anchor.href);}, 250 );}
}, 66);
return true;
}
erilot commented
This is a year old now, but can confirm the same (I'm downloading file responses from Guzzle, but same idea). The above proposed solution fixes it and the downloads work flawlessly when I set the mimetype to "application/octet-stream". Without adding this line, the download is just a textfile containing the filepath.