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

允我心安 提交于 2020-05-27 12:22:30

问题


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);
}


回答1:


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.



来源:https://stackoverflow.com/questions/61737871/is-it-possible-to-perform-a-resumable-upload-using-drive-files-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!