-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with File.Download.bytes on Mobile Safari and Chrome #17
Comments
I'm seeing the same behavior. If I comment out the call to It appears that the
In desktop Safari (and Chrome and Firefox), the same code produces:
This is even easier to see by creating a file with the following HTML:
Where Clicking on that link in mobile Safari opens the image in a page. Clicking on it in a desktop browser downloads the JPEG file. |
Is this still a problem on iOS 13? Pre-iOS 13, the download attribute was not supported by mobile safari. |
My tiny HTML snippet above now works in Safari under iOS 13. It offers to download or view the image when you click the link. It does NOT work in the latest Chrome or Brave under iOS 13. |
I have encountered this problem in Safari under iOS13.1. New page opens with the error message. When I've tried this snippet in console on the device and it works as expected, context window opens with options to view/download: var jsonObject = {"name": "John", "age": 30, "car": null};
var textFileAsBlob = new Blob([jsonObject], {type: 'text/plain'});
var downloadLink = document.createElement("a");
downloadLink.download = "file.json";
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
downloadLink;
//<a download="file.json" href="blob:https://localhost:3010/349f22ce-9b8a-44f6-9c56-9127503f6e65"/a>
downloadLink.click(); (From https://stackoverflow.com/a/49990108/6664068 ) |
Working smoothly on iOS. Have you inject your snippet into File.js? Also it could be potential memory leak (https://stackoverflow.com/questions/49209756/do-i-always-need-to-call-url-revokeobjecturl-explicitly). How about revoke it later? |
You can postpone revokingObjectURL by
There is probably required time which iOS needs after click event and the object cannot be revoke before it. |
Fixing iOS Safari blob immediate revoking. elm#17
Here's a roundabout way that we used to apply the above patch without having to change the const originalRevokeObjectURL = URL.revokeObjectURL;
URL.revokeObjectURL = function () {
setTimeout(() => {
originalRevokeObjectURL.apply(URL, arguments);
});
}; This could unfortunately affect other functionality that uses |
I had to use const originalRevokeObjectURL = URL.revokeObjectURL
URL.revokeObjectURL = function () {
setTimeout(() => {
originalRevokeObjectURL.apply(URL, arguments)
}, 200)
} |
I just copied good SSCCE example from #10
I started server with code above, went to it using mobile browsers (safari and crhome on iphone 7) and get weird errors, like trying to download files from server
here screenshots, Im sorry they are on russian, at least I can write translation of this :)
Safari is unabled to open page
Error: could not complete operation (WebkitBlobResource, error 1)
unable to access site page temporarily unavailable or permanently moved to new address
(tested on iphone 7)
And I cant figure out a way to save pdf file in my app for mobile users. The pdf file saves from server response after uploading form, (then it's generating and send back), so I dont have permanent link to file for easy way.
I will very appreciate for fixing this. Thank you!
The text was updated successfully, but these errors were encountered: