微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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



            }); 

原文地址:https://www.jb51.cc/android/431042.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐