Android 在PhoneGap中上载文件时获取文件名和扩展名

Android 在PhoneGap中上载文件时获取文件名和扩展名,android,cordova,Android,Cordova,我正在使用Android中的PhoneGap从图库上传图像,但我想做的是获取文件名及其扩展名,而我无法从imageuri获取该文件名及其扩展名,所以有人能告诉我如何找到一个吗 我的imageURI是content://media/external/images/media/876那么有没有办法通过使用这个imageURI获取文件条目并读取文件名和扩展名 function fileUpload(){ navigator.camera.getPicture(

我正在使用Android中的PhoneGap从图库上传图像,但我想做的是获取文件名及其扩展名,而我无法从imageuri获取该文件名及其扩展名,所以有人能告诉我如何找到一个吗

我的
imageURI
content://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){



            }); 

我也有同样的问题,我认为我找到了解决办法。我认为这不是最好的,但有可能;-)

从摄像头获取文件URI后,从文件URI解析文件系统,并在此文件条目中获取文件。这个文件(这里是filee)是一个名为type的变量,这是文件的mime类型


无论出于何种原因,这在cordova 3.4上都不起作用。我一直无法获得一个带有扩展名的常规uri…非常令人沮丧。有人能确认这是否适用于Android设备的Phonegap 3.4吗。。。我不想打开一个新的SO问题。在本例中,您可以通过执行entry来检索文件名为的实际本地目标。toURL()不起作用!
fullPath
toURL()
都不包含文件扩展名。@hunt不处理显示本机url而不是实际文件名的cordova。这真的很有帮助,谢谢
        function clickEvent() {

            navigator.camera.getPicture(cameraSuccess, cameraError, {
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM
            });
        }

        function cameraSuccess(file_URI) {
            window.resolveLocalFileSystemURI(file_URI, function(fileEntry) {
                fileEntry.file(function(filee) {
                    alert(filee.type); //THIS IS MIME TYPE
                }, function() {
                    alert('error');
                });

            }, onError);
        }

        function onError() {
            alert('fehler resolve file system');
        }

        function cameraError() {
            alert('fehler');
        }