【发布时间】: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