rndme / download

file downloading using client-side javascript
MIT License
2.28k stars 417 forks source link

Error downloading PDF from IE: InvalidCharacterError #29

Closed yamizukin closed 6 years ago

yamizukin commented 8 years ago

Using base64 encoded content, I can download text and images. I can also download PDFs in chrome.

However, I'm getting an error when downloading the same PDF in Internet Explorer 11.

index.txt

How can I fix this?

rndme commented 8 years ago

I can't reproduce this, but i don't have your file either...

Can you please post a link to a pdf file that doesn't work in IE11?

maillig commented 7 years ago

@yamizukin

I think i have found the problem:

  1. download.js uses the atob() method to decode the base64.
  2. It breaks in Internet Explorer 11 if the base64 string contains newlines.

Stackoverflow with simular issue

The fix is simple, just remove the line breaks:

var base64String = "DYWxpYnJpL0Vu Y29kaW5nL1dpbkFuc2lFbmNvZGluZy9Gb250RGVz....."

if (window.navigator && window.navigator.msSaveOrOpenBlob) { // IE specific code base64String= base64String.replace(/\s/g, ''); } And to download:

download("data:application/pdf;base64," + base64String, "fileName", "application/pdf");

rndme commented 6 years ago

base64 should not contain newlines anyway.