中断 googleapis 方法的执行

Interrupt the execution of a googleapis method

我使用 googleapis(Google API 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
    },
  });

As the NodeJS library's README.md exmplains, it uses gaxios underneath it and allows you to pass options either globally or for each call. See the list of gaxios request options.

如果出于某种原因您想手动处理何时中止而不是像设置超时这样更常见的事情,gaxios 有一个名为 signal.

的选项

参考资料