How to upload FILE_URI using Google Drive API: Insert File

前端 未结 3 1174
深忆病人
深忆病人 2021-01-03 05:52

On Android, I\'m trying to upload the output from Cordova/Phonegap getPicture() using Google Drive API: Insert File. Is there a way to do this using the FILE_URI instead of

3条回答
  •  Happy的楠姐
    2021-01-03 06:19

    I realize this is a bit old - but it now looks like you can use a FileReader in phoneGap.

    I haven't tested this yet, but something like this should also work, without the canvas hack.

    [EDIT - tested and revised the code below. works for me :D ]

    var cfn = function(x) { console.log(x) };
    var cameraOps = { quality: 50, destinationType: Camera.DestinationType.FILE_URI };
    navigator.camera.getPicture(function(imagePath) {
        window.resolveLocalFileSystemURL(imagePath, function(fileEntry) {
            fileEntry.file(function (file) {
                var reader = new FileReader();
                reader.onloadend = function(evt) {
                    console.log("read success!!!");
                    console.log(evt.target.result);
                };
                reader.readAsDataURL(file);
            }, cfn);
        }, cfn);
    }, cfn);
    

提交回复
热议问题