【问题标题】:How to restrict access to a file for a bucket on google cloud platform in node js如何在节点 js 中限制对谷歌云平台上存储桶文件的访问
【发布时间】:2018-02-23 05:56:52
【问题描述】:

这是我的 fileUploadService 文件:

import crypto from 'crypto';
var storage = require('@google-cloud/storage')();

uploadFile(req, bucket, next) {
    if (!req.file) {
        return next();
    }
    const gcsname = req.file.originalname;
    const file = bucket.file(gcsname);
    const stream = file.createWriteStream({
        metadata: {
            contentType: req.file.mimetype
        }
    });
    stream.on('error', (err) => {
        req.file.cloudStorageError = err;
        next(err);
    });
    /*stream.on('finish', () => {
        req.file.cloudStorageObject = gcsname;
        file.makePublic().then(() => {
            req.file.cloudStoragePublicUrl = this.getPublicUrl(gcsname);
            next();
        });
    });*/
    stream.end(req.file.buffer);
}

我必须让文件只可供发送者和接收者访问。有没有办法做到这一点?

【问题讨论】:

    标签: node.js angular express google-cloud-storage


    【解决方案1】:

    签名 URL 就是为此目的而设计的。

    https://cloud.google.com/storage/docs/access-control/signed-urls

    这个 SO question 有一个在 node.js 中生成签名 URL 的示例

    Create signed URLs for Google Cloud Storage with node.js for direct upload from browser

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2017-05-13
      • 2018-12-09
      相关资源
      最近更新 更多