简体   繁体   English

我如何从PhoneGap camera.getPicture获取File对象?

[英]How would I get a File object from PhoneGap camera.getPicture?

This is probably simple and covered by some combination of functions in PhoneGap's "Camera" plugin, "File" plugin, or "File-Transfer" plugin. 这可能很简单,并且由PhoneGap的“Camera”插件,“File”插件或“File-Transfer”插件中的某些功能组合覆盖。 I understand the user can select a file with: 我了解用户可以选择一个文件:

navigator.camera.getPicture(function (fileURI) {

    // *** need help here ***

}, function ()
    // handle errors
}, {
    destinationType: window.Camera.DestinationType.FILE_URI,
    sourceType: window.Camera.PictureSourceType.PHOTOLIBRARY,
    mediaType: window.Camera.MediaType.ALLMEDIA
});

I can also change to destinationType: window.Camera.DestinationType.DATA_URL if that makes a difference. 我也可以更改为destinationType: window.Camera.DestinationType.DATA_URL如果这有所不同。

My goal in the success handler is to get a File object ( https://developer.mozilla.org/en-US/docs/Web/API/File ). 我在成功处理程序中的目标是获取File对象( https://developer.mozilla.org/en-US/docs/Web/API/File )。

Something like this should do it. 这样的事情应该做到这一点。

navigator.camera.getPicture(function (fileURI) {

    window.resolveLocalFileSystemURL(fileURI, 
        function(fileEntry){
            alert("got image file entry: " + fileEntry.fullPath);
            // fileEntry.file() should return a raw HTML File Object
        },
        function(){//error}
    );

}, function (){
// handle errors
}, {
    destinationType: window.Camera.DestinationType.FILE_URI,
    sourceType: window.Camera.PictureSourceType.PHOTOLIBRARY,
    mediaType: window.Camera.MediaType.ALLMEDIA
});
window.resolveLocalFileSystemURI(fileURI, function(fileEntry) { /* your code here */ });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM