2015-08-16 33 views
0

我选择从galary图像并保存到应用程序目录,但是当图像的URL选择的文件名我面临的问题的发生是随机的数字,如:离子:科尔多瓦Getpicture中FileURL包含数在文件名

"/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}); 
      } 

请告诉我在哪里,我在做什么错了,我花了很多时间在此,谢谢提前。

回答

0

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

例如:

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