Search code examples
google-apps-scriptgoogle-drive-api

Is it possible to perform a resumable upload using Drive.Files.update()


I have two partially downloaded files (in my Drive), which I had split earlier. Both of these files together form the whole file. My goal is to merge (i.e join) them in Google Drive using Apps Script.

What I have done so far?

I used Drive.Files.insert to upload the first part. Then I tried Drive.Files.update to upload the second part to the first part's. It however overwrites the file.

My question : Is it possible to join/append files using that method?

NB: I could join the file in my PC with cat or type

Here is a sample code of my work:

  var resource = {
    title : 'Demo'
  };

  var mediaData = f1.getBlob();
  //f1 contains the file 1

  var headers = {
    'Content-Length' : f1.getSize(),
    'Content-Type': 'application/json; charset=UTF-8',
     uploadType : 'resumable'
  }

  var file = Drive.Files.insert(resource, mediaData, {headers : headers});

  var fileId = file.id;

  resource = {
    title : 'New Demo',
    mimeType : 'pdf'
  };

  mediaData = f2.getBlob();
  //f2 contains file 2

  headers = {
    'Content-Type' : 'application/json; charset=UTF-8',
    uploadType : 'resumable'
  };

  var file = Drive.Files.update(resource, fileId, mediaData, {headers : headers});

  Logger.log(file.id + '\n' + file.fileSize);
}


Solution

  • Quoting Tanaike's comments as answer.

    Unfortunately, in the current stage, the resumable upload cannot be achieved using Drive.Files.insert

    Also, if the size of all the files together is less than 50 MB:

    If the file size of "file A" + "file B" is less than 50 MB, one file can be created by merging the byte array retrieved from each file.