Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download image from PWA in Safari iOS13+

I am trying to implement downloading images from PWA. I am using

<a target="_blank"
   rel="noopener noreferrer"
   href="photo.url"
   download>Download image</a>

to achieve that. I am good on desktop Chrome and Safari and Chrome for Android. But when I am in a standalone mode (PWA) on Safari iOS 13 I can't close the opened window that was opened to save the file. On iOS 12 there was a button 'Done' and preview of the image.

I have tried solutions from here. But without success; Safari blocks the window.open().

window of download manager of iOS 13

like image 670
Денис Василенко Avatar asked Nov 18 '25 12:11

Денис Василенко


1 Answers

I also encountered the problem. I have a PWA in which images are shown and below the image there is a download button. When having simply assigned the image URL directly to the href of the download button, iOS (latest as of September 2021) did not show any "done" button or the reload icon.

What worked for me is below:

fetch('https://somedomain.tld/somefile.jpg')
.then(function(response) { 
    if (response.status !== 200) {
        alert('An error has occured (' + this.status + ')!');
    } else {
        response.blob().then(function(blob) {
            var objectURL = window.URL.createObjectURL(blob);
            document.getElementById('yourimageid').src = objectURL;
            document.getElementById('yourdownloadlinkid').href = objectURL;
        });
    }
});             

iOS Safari PWA download image done button

like image 189
Thommy Tomka Avatar answered Nov 20 '25 08:11

Thommy Tomka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!