【问题标题】:Interrupt the execution of a googleapis method中断 googleapis 方法的执行
【发布时间】:2021-07-22 16:33:32
【问题描述】:

我使用 googleapis(Google APIs Node.js 客户端)库方法googleapis.drive.files.create() 将文件上传到云端。 我将方法 a fs.ReadStream 作为参数之一 (fs.createReadStream())

有什么方法可以中断googleapis.drive.files.create()方法的执行(有或没有错误)?

const body = fs.createReadStream(filePath);
await this.googleDriveClient.files.create(
  {
    resource: {
      name: fileName,
      parents: [parentIds]
    },
    media: {
      mimeType: 'image/gif',
      body
    },
  });

【问题讨论】:

  • 您能否提供更多有关您为什么需要它的背景信息?
  • 请阅读How to Ask 编辑您的问题并包括minimal reproducible example 并更详细地描述您的问题。
  • @Martí 有一种情况是互联网连接丢失并且此方法冻结我想以某种方式将控制权交还给调用代码const body = fs.createReadStream(filePath); await this.googleDriveClient.files.create({ resource: { name: fileName, parents: [parentIds] }, media: { mimeType: 'audio/mpeg', body }, });

标签: node.js google-drive-api google-api-nodejs-client


【解决方案1】:

As the NodeJS library's README.md exmplains,它在它下面使用 gaxios,并允许您在全局或每次调用中传递选项。 See the list of gaxios request options.

如果出于某种原因您想要手动处理何时中止而不是设置超时等更常见的操作,gaxios 有一个名为 signal 的选项。

参考文献

【讨论】:

    猜你喜欢
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-10
    • 2019-04-19
    • 1970-01-01
    • 2020-06-28
    相关资源
    最近更新 更多