1

I'm working on download a binary file, the extension is '.pfx', from iOS.

I generated data URI(data:URL) and invoke it using a tag.

The problem is that the download attribute works on Safari, but is not working on Chrome.

The binary file named as just 'document' at Chrome.

Here is my code;

var reader = new FileReader();
reader.onload = (e) => {
    var a = document.createElement("a");
    a.style.display = "none";
    document.body.appendChild(a);

    a.href = reader.result;

    // Use download attribute to set set desired file name
    a.setAttribute("download", fileName);
    a.setAttribute("target", "_blank");

    // Trigger the download by simulating click
    a.click();

    // Cleanup
    document.body.removeChild(a);
};
reader.readAsDataURL(blob);

I tested the code on iOS 13 and iPhone 11 pro.

안구환
  • 13
  • 5

0 Answers0