How to upload FILE_URI using Google Drive API: Insert File

前端 未结 3 1173
深忆病人
深忆病人 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:23

    Thanks to Arun for pointing me in the right direction. I ended up using this javascript function, which was based off http://jsfiddle.net/jasdeepkhalsa/L5HmW/

    function getBase64Image(imgElem) {
    // imgElem must be on the same server otherwise a cross-origin error will be thrown "SECURITY_ERR: DOM Exception 18"
        var canvas = document.createElement("canvas");
        canvas.width = imgElem.clientWidth;
        canvas.height = imgElem.clientHeight;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(imgElem, 0, 0);
        var dataURL = canvas.toDataURL("image/jpeg");
        dataURL = dataURL.replace(/^data:image\/(png|jpg|jpeg);base64,/, "");
        return dataURL;
    }
    

提交回复
热议问题