【问题标题】:How to restrict re-uploading after uploading of file using singed url in google cloud store in Node.js?如何在 Node.js 的谷歌云存储中使用签名 url 上传文件后限制重新上传?
【发布时间】:2020-08-22 12:00:35
【问题描述】:

借助

https://github.com/googleapis/nodejs-storage/blob/master/samples/generateV4UploadSignedUrl.js

var {Storage} = require('@google-cloud/storage')

var storage = new Storage({
    projectId: "projectId",
    credentials: {
        client_email: "clientEmail",
        private_key: "privateKey"
    }
})

var generateUploadSignedUrl = async function(bucketName, remoteFilename, expires) {
    const options = {
        version: 'v4',
        action: 'write',
        expires: expires,
        contentType: 'application/octet-stream',
      }
    var url = await storage.bucket(bucketName).file(remoteFilename).getSignedUrl(options)
    return url
}

我可以使用 singed url 上传文件。
但我想限制上传后我不能再次上传。如何添加此类策略?

我在policy-document上看了看,但找不到限制重新上传的相关条件。

【问题讨论】:

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


    【解决方案1】:

    这是不可能的。

    如果您使用 gsutil,则可以使用标志 -n。正如this 文档所说,“当指定时,目的地的现有文件或对象将不会被覆盖。任何被此选项跳过的项目都将被报告为被跳过”。

    另一方面,使用客户端库,没有这样的事情。不过,首先你可以检查是否the file exists,如果不是,复制它。

    【讨论】:

    猜你喜欢
    • 2018-08-30
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2018-09-18
    • 2020-06-28
    • 2016-01-18
    • 2018-06-16
    • 2014-07-11
    相关资源
    最近更新 更多