简体   繁体   中英

Cordova Plugins Photo Library Plugin: Get downloaded picture file_uri path

I am using Cordova Plugins Photo Library Plugin to download picture from server or internet. I successfully downloaded picture from internet and server. However, I fail to get the path of picture. I need the file_uri path so that I can display the picture by showing the file_uri path.

The following is my code.

 var url = 'https://images-cdn.9gag.com/photo/am9znpv_700b.jpg'; 
    var album = 'DRDMChat';
    cordova.plugins.photoLibrary.saveImage(url, album, 
        function (libraryItem) {
            var ImagePath = libraryItem.cdvphotolibrary
            alert(libraryItem.cdvphotolibrary);
        }, function (err) {
            alert(err);
        });

You can get the path to the photo using the photoURL attribute of libraryItem .

Here is the code -

var url = 'https://images-cdn.9gag.com/photo/am9znpv_700b.jpg'; 
var album = 'DRDMChat';
cordova.plugins.photoLibrary.saveImage(url, album, 
    function (libraryItem) {

        //log or alert the below attributes
        console.log(libraryItem.id);          // ID of the photo 
        console.log(libraryItem.photoURL);    // Cross-platform access to photo 
        console.log(libraryItem.thumbnailURL);// Cross-platform access to thumbnail 
        console.log(libraryItem.fileName);

        var ImagePath = libraryItem.photoURL //Photo URL Access
        alert(libraryItem.photoURL);
    }, function (err) {
        alert(err);
    });

Refer Displaying photos Section of cordova-plugin-photo-library for other attributes of libraryItem .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM