gpt4 book ai didi

android - 在 PhoneGap 中上传文件时获取文件名和扩展名

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:45:42 25 4
gpt4 key购买 nike

我在 Android 中使用 PhoneGap 从图库上传图片,但我想做的是获取文件名及其扩展名,我无法从 获取它imageuri 任何人都可以告诉我如何找到一个

我的 imageURIcontent://media/external/images/media/876 所以有没有办法通过使用这个 imageURI 并读取文件名和扩展名 ?

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){



});

关于android - 在 PhoneGap 中上传文件时获取文件名和扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22258757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com