是否可以使用Drive.Files.update()执行断点续传 [英] Is it possible to perform a resumable upload using Drive.Files.update()

查看:86
本文介绍了是否可以使用Drive.Files.update()执行断点续传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个部分下载的文件(在我的云端硬盘中),这些文件是我先前拆分的.这两个文件共同构成了整个文件.我的目标是使用Apps脚本将其合并(即加入)在Google云端硬盘中.

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?

我用Drive.Files.insert上传了第一部分.然后我尝试Drive.Files.update将第二部分上传到第一部分.但是它将覆盖文件.

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?

注意:我可以使用cattype

这是我的工作的示例代码:

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

推荐答案

引用Tanaike的评论作为答案.

不幸的是,在当前阶段,无法使用Drive.Files.insert

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

此外,如果所有文件的总大小小于50 MB:

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

如果文件A" +文件B"的文件大小小于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.

这篇关于是否可以使用Drive.Files.update()执行断点续传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆