【问题标题】:Google Cloud Storage - how to receive specific generation of file in Node.JSGoogle Cloud Storage - 如何在 Node.JS 中接收特定生成的文件
【发布时间】:2018-03-27 09:21:17
【问题描述】:

我正在使用 @google-cloud/storage 访问 GCS API。启用版本控制后,我尝试使用以下代码获取特定生成的文件:

bucket.file(`${name}#${generationId}`).download({
    destination
}).then(() => {
    res.set({
        'Content-Type': 'image/jpeg'
    });
    return res.status(200).sendFile(destination);
})

其中name 是完整的对象名称,generationId 包含文件的生成编号。

但是,如果我在 Google Cloud Functions 中执行上述代码,我会收到以下错误消息:

ApiError: No such object: my-bucket/image-mxmg569kdvnby6z85mi#1522107649220516

我确定该文件和生成存在,因为我已使用 JSON API 资源管理器对其进行了检查。我的猜测是@google-cloud/storage 不支持文件版本控制(还),文档不包含任何信息。有人有这方面的经验吗?

【问题讨论】:

标签: node.js google-cloud-platform google-cloud-storage


【解决方案1】:

如果在实例化 File 对象时设置options.generation,它应该可以工作! https://github.com/googleapis/nodejs-storage/blob/4f4f1b4043c4f70ee99f051499ac62e893abdde0/src/file.js#L82

bucket.file(name, { generation: generationId })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-16
    • 2019-08-22
    • 2012-04-19
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2020-01-15
    相关资源
    最近更新 更多