【问题标题】:Is it possible to prevent web clients from setting Cache-Control when they have permission to upload to Google Cloud Storage? [closed]是否可以阻止 Web 客户端在有权上传到 Google Cloud Storage 时设置 Cache-Control? [关闭]
【发布时间】:2021-06-21 20:20:12
【问题描述】:

客户端正在调用ref.put(file, metadata) 以上传图像。 cacheControlSettableMetadata 定义的一部分,可以传递给 putupdateMetadata。有没有办法禁止客户设置这个?我知道我可以使用云函数异步更新它,但随后客户端可以稍后调用updateMetadata,如果我有一个触发元数据更新以更新元数据的云函数,它会进入无限循环(在模拟器)。

【问题讨论】:

  • 您是否授予客户上传对象的权限?如果是,他们可以设置元数据。使用有关客户授权的详细信息编辑您的问题。
  • 客户端有上传对象的权限。
  • 通过什么方法(公共存储桶、IAM 身份、服务帐户)?使用详细信息编辑您的问题。
  • 他们通过云存储规则获得权限 - 例如具有 UID 的 firebase 用户可以上传到 images/{UID}

标签: firebase google-cloud-storage firebase-security


【解决方案1】:

如果用户能够直接在 Firebase 存储中上传文件,则假定他们也有权定义元数据。您可以设置一个云功能来编辑上传后的元数据,或者直接从云功能与您的上传一起处理它。这一切都取决于您在应用中的流程。

一个解决方案是有一个用户上传到的专用目录,云功能将文件迁移和处理到另一个目录,这将阻止用户更新元数据。

您始终可以在客户端应用程序中执行以下操作:

/ Create a reference to the file whose metadata we want to change
var forestRef = storageRef.child('images/forest.jpg');

// Create file metadata to update
var newMetadata = {
  cacheControl: 'public,max-age=300',
  contentType: 'image/jpeg'
};

// Update metadata properties
forestRef.updateMetadata(newMetadata)
  .then((metadata) => {
    // Updated metadata for 'images/forest.jpg' is returned in the Promise
  }).catch((error) => {
    // Uh-oh, an error occurredd!
  });

来源:https://firebase.google.com/docs/storage/web/file-metadata#update_file_metadata

【讨论】:

    猜你喜欢
    • 2015-11-20
    • 1970-01-01
    • 2014-01-21
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2016-06-17
    • 2016-12-01
    相关资源
    最近更新 更多