将图像保存到图库(相机胶卷)Ionic 2

时间:2017-06-23 09:10:38

标签: cordova ionic-framework ionic2 cordova-plugins

我将图像从服务器保存到设备上的本地路径

downLoad() {
    this.http.downloadFile('http://example.com/files/files/image.jpg', {}, {}, 'image.jpg')
    .then(data => {
        console.log(data) ;
    })
    .catch(error => {

        console.log(error) ;

    });

}

但图像保存不在照片库中。怎么修理?

1 个答案:

答案 0 :(得分:3)

您可以使用此插件执行此操作:https://github.com/terikon/cordova-plugin-photo-library

添加插件后,您可以保存以下图片:

var url = 'file:///...'; // file or remote URL. url can also be dataURL, but giving it a file path is much faster
var album = 'MyAppName';
cordova.plugins.photoLibrary.saveImage(url, album, function (libraryItem) {}, function (err) {});