我在Android中使用PhoneGap从图库中取代了一个图像,但我想要的是获取文件名及其扩展名,我无法从imageuri获取它所以任何人都可以告诉我如何找到一个
我的imageURI是内容:// media / external / images / media / 876所以有没有办法通过使用这个imageURI获取fileEntry并读取文件名和扩展名?
function fileUpload(){
navigator.camera.getPicture(
uploadPhoto,function(message) { alert('get picture Failed'); },{
quality : 50,destinationType : navigator.camera.DestinationType.FILE_URI,sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="uploaded_file";
alert(imageURI);
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI,encodeURI("http://www.mydomain.com/mobile_upload.PHP"),win,fail,options);
}
function win(r) {
alert("WIN" +r.response);
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("error");
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
最佳答案
我找到了答案,这里是代码
window.resolveLocalFileSystemURI(imageURI,function(entry){
console.log("****************HERE YOU WILL GET THE NAME AND OTHER PROPERTIES***********************");
console.log(entry.name + " " +entry.fullPath);
},function(e){
});