如何从离子图片库下载图像



我正在使用离子画廊指令并使用图像网址在离子画廊内显示图像。如何下载相同的图像?

任何帮助将不胜感激。

我认为为此您想从这里使用ng-cordova File Transfer Plugin

在此插件中,您必须选择下载文件并存储在SD卡中。

源代码示例

            $scope.downloadFile = function() {
               //URL CONTAINTS IMAGE PATH
               var url = "http://your_ip_address/images/my.jpg";
               var filename = url.split("/").pop();
               alert(filename);
               var targetPath = cordova.file.externalRootDirectory + filename;
               var trustHosts = true
               var options = {};
               alert(cordova.file.externalRootDirectory);
               $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
                 .then(function(result) {
                   // Success!
                   alert(JSON.stringify(result));
                 }, function(error) {
                   // Error
                   alert(JSON.stringify(error));
                 }, function (progress) {
                   $timeout(function () {
                     $scope.downloadProgress = (progress.loaded / progress.total) * 100;
                   })
                 });
            }

仍然 如果您遇到问题,那么图像不显示在图库中的原因是在下载或创建文件夹后需要更新Android媒体。我有同样的问题,但我想我在这里找到了解决方案。

这是一个插件,允许Cordova仅使用以下方法调用媒体扫描仪:

 window.MediaScannerPlugin(successCallback, failureCallback)

如需更多帮助,请查看 这里, 这里 和 这里.

希望这对你有帮助!!

最新更新