【问题标题】:Ionic: Cordova GetPicture FileURL contain Number at the place of file nameIonic:Cordova GetPicture FileURL 在文件名位置包含数字
【发布时间】:2015-08-18 23:21:15
【问题描述】:

我正在从 galary 中选择图像并保存到应用程序目录中,但是当图像选择 url 中的文件名是随机数时遇到问题:

"/media/external/images/media/26183"

我没有得到确切的文件名,因此当文件要复制文件时未找到错误是抛出我的代码以获取和保存是:

     $scope.ChangeProfile = function() {
      var options = {
        quality: 30,
        destinationType: Camera.DestinationType.NATIVE_URI,
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
         encodingType: Camera.EncodingType.JPEG,
         mediaType:Camera.MediaType.PICTURE
      };

      navigator.camera.getPicture( OnCameraSuccess, OnCameraError, options);


    };
 function OnCameraSuccess(imageURI) {
          console.log(imageURI);
           window.resolveLocalFileSystemURL(imageURI,OnSucessFilePath, onErrorFilePath); 
          }
          function onErrorFilePath(error){
              console.log(error);
          }
          function OnSucessFilePath(fileEntry){
              console.log(fileEntry);
              var FilePath=fileEntry.nativeURL;
          var name = FilePath.substr(FilePath.lastIndexOf('/') + 1);
          var namePath = FilePath.substr(0, FilePath.lastIndexOf('/') + 1);
            var newName = "Profile_Pic";
          $cordovaFile.removeFile(cordova.file.dataDirectory, newName)
          .then(function (success) {
              console.log(success);
          }, function (error) {
              console.log(error);
          });
          // var newName = makeid() + name;
          $cordovaFile.copyFile(namePath, name, cordova.file.dataDirectory, newName)
          .then(function(info) {
          console.log(info);
            ProfileImage.Image = cordova.file.dataDirectory+newName;
            $scope.PicUpload = true;
              },
            function(err){
            console.log(err);
            });
          }
           function OnCameraError(err){
            console.log(err);
            $ionicLoading.show({template: 'error in Loading', duration:500});
          }

请告诉我哪里做错了,我花了很多时间在这上面,提前谢谢。

【问题讨论】:

    标签: ionic-framework cordova-plugins


    【解决方案1】:

    如果您在 Android 平台上运行您的应用程序,那么我认为您需要解析原生 uri。可以使用this plugin解决。

    例子:

    window.FilePath.resolveNativePath(YourNativeURI,
                    function (result) {
                        console.log('Resolving file path: ' + result);                        
                    }, function (error) {
                        console.log(error);
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 2012-07-08
      • 2018-01-01
      • 2012-08-15
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多