【问题标题】:Cloud Storage the deleted file still accessibleCloud Storage 已删除的文件仍可访问
【发布时间】:2021-05-26 01:17:00
【问题描述】:

我正在从 Cloud Storage 中删除一个 JSON 文件。但是,我删除的这个文件仍然可以访问。我知道这听起来很傻。当我列出云存储中存在的文件时,该文件未列出。但是,我可以使用 URL 访问此文件。

我会试着给你举个例子。

我正在使用 Postman 从云存储中调用文件:

[
    {
        "_id": "60ad0e33b7161e270d7f9bf2",
        "id": 1,
        "city": "Rotterdam",
        "hours_0_sun": 2.4,
        "daily_0_temp_day": 11.5,
        ....
    },
    {
      ...
    }
]

当我删除文件时

const key = `someid-someid.json`;
const bucket = storage.bucket(process.env.GCLOUD_BUCKET_NAME);
const file = bucket.file(key);
const response = await file.delete();

然后再次调用文件:

[
    {
        "_id": "60ad0e33b7161e270d7f9bf2",
        "id": 1,
        "city": "Rotterdam",
        "hours_0_sun": 2.4,
        "daily_0_temp_day": 11.5,
        ....
    },
    {
      ...
    }
]

文件仍然可以访问...

当我尝试从存储中获取文件时:

            //Find file
const options = {
   prefix: `someid-someid.json`
};

let files = await storage.bucket(process.env.GCLOUD_BUCKET_NAME).getFiles(options);
console.log(files);

控制台:

[[]]

这快把我逼疯了。这是正常的吗?如何彻底删除文件?

注意:当我删除文件时,我也无法从存储浏览器中看到该文件。所以文件在存储中不存在。但仍然可以访问...

【问题讨论】:

  • 该文件是否存储在 CDN 缓存中,而您正在检索该文件的缓存版本?
  • 你是我的英雄。非常感谢。是的,缓存是问题所在。我会尽快回答问题

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


【解决方案1】:

感谢@Kolban,我发现了这个问题,他在 cmets 中提到了 CDN 缓存。

我在将文件上传到云存储时设置了 1 小时缓存选项,但我完全忘记了。

我将 1 小时改为 1 分钟,问题解决了!

await bucket
  .upload(filePath, {
    destination: key,
    gzip: true,
    metadata: {
       cacheControl: "public, max-age=60" // 1 minute caching
    },
    public: true
});

【讨论】:

  • 错误的方法 - 一分钟 CDN 缓存有什么好处?而是使缓存无效。
猜你喜欢
  • 1970-01-01
  • 2018-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-09
  • 1970-01-01
  • 2020-12-11
相关资源
最近更新 更多