How to upload FILE_URI using Google Drive API: Insert File

前端 未结 3 1155
深忆病人
深忆病人 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条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 06:21

    Yes you can....

    Specify Destination Type as FILE_URI itself and in imagedata you will be getting the images file uri place it in a image tag and then place it inside HTML5 canvas and canvas has one method called toDataURL where you will be able to get the base64 of the corresponding image.

    function onSuccess(imageData)
         {
    
                    var $img = $('');
                    $img.attr('src', imageData);
                    $img.css({position: 'absolute', left: '0px', top: '-999999em', maxWidth: 'none', width: 'auto', height: 'auto'});
                    $img.bind('load', function() 
                    {
                        var canvas = document.createElement("canvas");
                        canvas.width = $img.width();
                        canvas.height = $img.height();
                        var ctx = canvas.getContext('2d');
                        ctx.drawImage($img[0], 0, 0);
                        var dataUri = canvas.toDataURL('image/png');
    
                    });
                    $img.bind('error', function() 
                    {
                        console.log('Couldnt convert photo to data URI');
                    });
    
        }
    

提交回复
热议问题