4

i want to integrate google drive in angular 5/6 web app, how can i upload doc/file to google drive from angular 5/6 web app. is it possible or not, if yes then how?

can anyone share complete process with coding.

i tried google drive api but there is nothing available any documentation regarding implementing in angular 5.

i tried from: https://developers.google.com/drive/api/v2/reference/files/insert

    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);
  }
}
Dinesh
  • 71
  • 2
  • 10

0 Answers0