3

This has been asked several times, but most of these questions are unanswered

I'm downloading a file like below, and it seems to work fine. However .. it does not show up in the iOS, ehm, gallery. That is, in the 'photos' application.

    var fileTransfer = new FileTransfer();
var encurl = encodeURI(url);
var filename = url.split('/').slice(-1)[0];
var filepath = "foo/"+filename;

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var syspath = fileSystem.root.toURL() + '/' + filepath;
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        encurl,
        syspath,

        function (entry) {
            foo.debug("Download success "+syspath);
        },
        function (error) {
            foo.error("Download failed with error "+error.code+' '+syspath);
        }
    );
}, function (evt) {
    foo.error("Filesystem failed with error "+evt.target.error.code);

});

and the result is

[Log] Download success file:///var/mobile/Applications/68DE0AD9-FBD2-4D82-92C0-2B7634B218D5/Documents//foo/20141030-153810-editor.jpg (console-via-logger.js, line 173)

hurray. now, how do you open the download, using just your fingers, on ios ?

commonpike
  • 10,499
  • 4
  • 65
  • 58
  • Hey, have you found something since then ? – Jeremy Belolo Mar 26 '15 at 10:31
  • Yes, see http://stackoverflow.com/questions/21577230/phonegap-save-image-from-url-into-device-photo-gallery - the answer by M165437 and my comments. Dont be baffled by the Canvas2Image (like I was). I have this in production on ios, android and windows now. – commonpike Mar 26 '15 at 11:41
  • What I don't understand is that the image IS actually on the phone, but doesn't shows up in the gallery. Why is that ? Is it an encoding issue ? Really strage. – Jeremy Belolo Mar 26 '15 at 12:00
  • To be more in the details, I can't use that because I have the same issue with photos AND videos, that are correctly downloaded but doesn't shows up in the gallery. And canvas can't be used for videos. – Jeremy Belolo Mar 26 '15 at 12:15
  • 1
    Yes, funny huh ? Downloaded files are messing up your device, and invisible. The problem is, the *media scanner* has to run. Android does that on reboot, for example. There is supposedly code to trigger, but never got it to work - see http://stackoverflow.com/questions/22784791/phonegap-3-3-0-pass-downloaded-file-cdvfile-url-to-media-scanner – commonpike Mar 26 '15 at 14:22
  • Please see below url. This is work for me and work with ios and android http://stackoverflow.com/a/38590480/4060572 – Parth Devmorari Jul 26 '16 at 13:02

2 Answers2

1

I would mark this as a duplicate of Phonegap - Save image from url into device photo gallery

I was happy with the answer by M165437 and my comments. That answered my question.

Community
  • 1
  • 1
commonpike
  • 10,499
  • 4
  • 65
  • 58
  • Ok, funny :-) I ask a question, get no answers for 9 months, decide to mark my own answer as a duplicate, which I can't, so I add a useful pointer and accept that myself, and then I get downvotes for that :-D – commonpike Sep 12 '17 at 13:24
0

Try to download by using https://www.npmjs.com/package/com-cordova-image-save-to-gallery plugin. It will download a picture from a given URL and save it to IOS Photo Gallery.

Cordova plugin add https://github.com/valwinjose007/cordova-image-save-to-gallery.git

How to use:

declare var CordovaImageSaveToGallery: any;

CordovaImageSaveToGallery.downloadFromUrl('https://picsum.photos/200/300',(res)=>{
    //download success
},(err)=>{
    //error on download
});
Alwin Jose
  • 696
  • 1
  • 5
  • 13