phonegap将图像从网址保存到相册

时间:2014-08-01 00:41:57

标签: javascript android image cordova

如何使用phonegap for android

将图像从网址保存到相册

我的代码是:

<a href="#" onclick="saveToPhotoAlbum('https://build.phonegap.com/images/icon.png', true);">Click to save!</a>

1 个答案:

答案 0 :(得分:0)

您需要使用文件传输插件

File transfer plugin link

function saveToPhotoAlbum(myuri)
{
var fileTransfer = new FileTransfer();
var uri = encodeURI(myuri);
var filePath="cdvfile://localhost/persistent/myImageFolder/myImage.jpg";

fileTransfer.download(
    uri,
    filePath,
    function(entry) {
        console.log("download complete: " + entry.fullPath);
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
    },
    false,
    {
        headers: {
            "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
        }
    }
);
}

<a href="#" onclick="saveToPhotoAlbum('https://build.phonegap.com/images/icon.png');">Click to save!</a>