简体   繁体   English

科尔多瓦文件传输插件下载未显示在图片库中

[英]cordova filetransfer plugin download doesnt show up in image gallery

I have this code that downloads an image from a URL and saves in my phone device but the problem is that it doesnt show up in the image gallery of the phone device rather it shows up in the file storage directory. 我有这段代码可以从URL下载图像并保存在我的电话设备中,但是问题是它没有显示在电话设备的图像库中,而是显示在文件存储目录中。 So, i would like to have it show up in the image gallery. 因此,我想将其显示在图库中。

$scope.downloadImage = function(images) {
    var imageName = angular.fromJson(images);
    $scope.$applyAsync(function() {
      $scope.indexchosen === undefined ? $scope.indexchosen = 0 : $scope.indexchosen;
      console.log($scope.indexchosen)
      index = $scope.indexchosen;
      imageToDownload = imageName[index].filename; 
    })

    $scope.$applyAsync(function() {
      window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
    });

    function onSuccess(fileSystem) {
      var directoryEntry = fileSystem.root; 
      countImage+=1; 

      var name = countImage + '-' + imageToDownload.split('/').pop();
      var imageUrl = encodeURI(decodeURIComponent(AppSettings.baseApiUrl + imageToDownload));
      var fp = fileSystem.root.toURL();

      var filepath = fp + '/' + name;
      console.log(filepath)
      var ft = new window.FileTransfer();
      var f =  ft.download(imageUrl, filepath,
        function (entry) {
          $cordovaToast.show("Image Saved", "long", "bottom");
        },
        function (error) {
        }
      );
    }
    function onError(error) {
    }
  }

Any help is appreciated thanks. 任何帮助表示赞赏,谢谢。

If download success, you should re-scan your device storage, because Cordova does not know if the file is downloaded. 如果下载成功,则应重新扫描设备存储,因为Cordova不知道文件是否已下载。

so i made a plugin , 所以我做了一个插件

It is a plugin that updates the gallery after downloading. 它是一个在下载后更新图库的插件。

https://github.com/pouu69/cordova-plugin-gallery-refresh

尝试重新启动设备,然后检查图库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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