Ionic framework Ionic:Cordova GetPicture文件URL在文件名处包含数字
我正在从galary中选择图像并保存到应用程序目录中,但当图像选择时,我面临一个问题url中的文件名是随机数,如:Ionic framework Ionic:Cordova GetPicture文件URL在文件名处包含数字,ionic-framework,cordova-plugins,Ionic Framework,Cordova Plugins,我正在从galary中选择图像并保存到应用程序目录中,但当图像选择时,我面临一个问题url中的文件名是随机数,如: "/media/external/images/media/26183" 我没有得到确切的文件名,因此,当文件要复制时,文件找不到错误抛出我的代码,用于获取和保存的代码是: $scope.ChangeProfile = function() { var options = { quality: 30, destinationT
"/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});
}
请告诉我哪里做错了,我在这方面花了很多时间,提前谢谢。如果您在Android平台上运行应用程序,那么我认为您需要解析本机uri。您可以使用来解决它 例如:
如果您在Android平台上运行应用程序,那么我认为您需要解析本机uri。您可以使用来解决它 例如:
window.FilePath.resolveNativePath(YourNativeURI,
function (result) {
console.log('Resolving file path: ' + result);
}, function (error) {
console.log(error);
});