Como fazer o upload de FILE_URI usando a API do Google Drive: Inserir arquivo

No Android, estou tentando fazer o upload da saída do Cordova / Phonegap getPicture () usando a API do Google Drive: Inserir arquivo. Existe uma maneira de fazer isso usando o FILE_URI em vez de DATA_URL (base64)?

Eu tentei Camera.DestinationType.DATA_URL primeiro, mas ele não retornou os dados da Base64 como deveria, apenas retornou a mesma coisa que FILE_URI. Agora, estou tentando descobrir como passar FILE_URI para o arquivo de inserção do Google Drive (que usa o Base64). Existe uma maneira de converter FILE_URI para Base64?

Código Cordova:

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

function onSuccess(imageURI) {
    var image = document.getElementById('myImage');
    image.src = imageURI;

    // need to do something like this:
    var fileData = ConvertToBase64(imageURI);
    insertFile(fileData);
}

Código do Google Drive:

/**
 * Insert new file.
 *
 * @param {File} fileData File object to read data from.
 * @param {Function} callback Function to call when the request is complete.
 */
function insertFile(fileData, callback) {
  const boundary = '-------314159265358979323846';
  const delimiter = "\r\n--" + boundary + "\r\n";
  const close_delim = "\r\n--" + boundary + "--";

  var reader = new FileReader();
  reader.readAsBinaryString(fileData);
  reader.onload = function(e) {
    var contentType = fileData.type || 'application/octet-stream';
    var metadata = {
      'title': fileData.fileName,
      'mimeType': contentType
    };

    var base64Data = btoa(reader.result);
    var multipartRequestBody =
        delimiter +
        'Content-Type: application/json\r\n\r\n' +
        JSON.stringify(metadata) +
        delimiter +
        'Content-Type: ' + contentType + '\r\n' +
        'Content-Transfer-Encoding: base64\r\n' +
        '\r\n' +
        base64Data +
        close_delim;

    var request = gapi.client.request({
        'path': '/upload/drive/v2/files',
        'method': 'POST',
        'params': {'uploadType': 'multipart'},
        'headers': {
          'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
        },
        'body': multipartRequestBody});
    if (!callback) {
      callback = function(file) {
        console.log(file)
      };
    }
    request.execute(callback);
  }
}

questionAnswers(3)

yourAnswerToTheQuestion