使用phonegap时,window.resolveFileSystemURI()和window.requestFileSystem都不存在?

时间:2014-02-04 10:21:06

标签: javascript android cordova devexpress

我刚刚开始使用Phonegap,不幸的是我在一个问题上被粉刷了。使用相机api成功捕获图像,但我想将图片从缓存移动到我的Android设备的选定文件夹中。我浏览了整个互联网,有些人使用window.resolveFileSystemURI,但它在我的项目中并不存在。

TestCamera.home = function (params) {
//Callback function when the picture has been successfully taken
function onPhotoDataSuccess(imageData) {
    // Get image handle
    var smallImage = document.getElementById('smallImage');

    // Unhide image elements
    smallImage.style.display = 'block';
    smallImage.src = imageData;
    alert(imageData);
    //movePic(imageData);

}

function onPhotoURISuccess(imageURI) {
    var largeImage = $('#largeImage');
    largeImage.css('display', 'block');
    largeImage.attr('src', imageURI);
}
function getPhoto(source) {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: TestCamera.destinationType.FILE_URI,
        sourceType: source
    });
}
function onFail(message) {
    alert('Failed because: ' + message);
}
function movePic(file) {
    window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError);
}

//Callback function when the file system uri has been resolved
function resolveOnSuccess(entry) {
    var d = new Date();
    var n = d.getTime();
    //new file name
    var newFileName = n + ".jpg";
    var myFolderApp = "EasyPacking";

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
        //The folder is created if doesn't exist
        fileSys.root.getDirectory(myFolderApp,
                { create: true, exclusive: false },
                function (directory) {
                    entry.moveTo(directory, newFileName, successMove, resOnError);
                },
                resOnError);
    },
resOnError);

}

//Callback function when the file has been moved successfully - inserting the complete path
function successMove(entry) {
    //I do my insert with "entry.fullPath" as for the path
    alert(entry);
}

function resOnError(error) {
    alert(error.code);
}
var viewModel = {
    capturePhoto: function (e) {
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
            quality: 50,
            destinationType: TestCamera.destinationType.FILE_URI

        });
    },
    capturePhotoEdit: function (e) {
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
            quality: 20,
            allowEdit: true,
            destinationType: TestCamera.destinationType.FILE_URI
        });
    },
    photoLibrary: function (e) {
        getPhoto(TestCamera.pictureSource.PHOTOLIBRARY);
    },
    photoAlbum: function (e) {
        getPhoto(TestCamera.pictureSource.SAVEDPHOTOALBUM);
    }
};

return viewModel;

};

!window [resolveFileSystemURI()]返回true, 我错过了一个文件或什么? 任何帮助将非常感激 :) Daan Helsloot

1 个答案:

答案 0 :(得分:2)

我认为您应该首先将文件插件添加到项目中:

phonegap local plugin add org.apache.cordova.file
phonegap local plugin add org.apache.cordova.file-transfer

顺便说一下,我有另一个问题的解决方案,您可以使用以下代码检索捕获图像的base64:

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.DATA_URL
});

然后将base64编码保存到您想要的任何目录