Search code examples
cordovaionic-frameworkcapacitor-plugin

ionic5 Capacitor "media scanner plugin" after use File Transfer plugin to download image to photo gallery


It a ionic5 app build with Cordova Capacitor. There's a function using "File Transfer" plugin to download image to local phone photo gallery. I can success download the image, but it don't show in phone's gallery app(with file browser app can find it). I see there is a Cordova plugin "cordova-plugin-mediascanner", but can not find Capacitor version, Is there a Capacitor plugin? Or other way to do this?


Solution

  • I used another plugin "photoLibrary" to solved this:

    var fileTransfer = new FileTransfer();
    var uri = encodeURI("http://some.server.com/download.php");
    fileTransfer.download(uri, 'cdvfile://localhost/temporary/path/to/image.jpg', 
    function (entry) {
    var targetPath= entry.toURL();
    **cordova.plugins.photoLibrary.saveImage(targetPath, "myApp", function** 
    (libraryItem) {
      ...
     });
    }, function(error) {
     ...
    });