download icon indicating copy to clipboard operation
download copied to clipboard

Incorrect mime type HTML5 anchor

Open acourdavault opened this issue 4 years ago • 1 comments

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;
			}

acourdavault avatar Jul 15 '19 18:07 acourdavault

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.

Possibly also related to https://github.com/rndme/download/issues/86 and https://github.com/rndme/download/pull/78.

erilot avatar Aug 21 '20 20:08 erilot