我正在从云存储中删除一个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);控制台:
[[]]这快把我逼疯了。这是正常的吗?怎样才能完全删除该文件?
注意:当我删除该文件时,我也无法从存储浏览器中看到该文件。所以文件在存储中不存在。但仍然可以访问...
发布于 2021-05-26 01:17:01
多亏了@Kolban,我发现了这个问题,他在评论中提到了CDN缓存。
我设置了一个小时的缓存选项,而我上传文件到云存储,这是我完全忘记了。
我把1小时改成了1分钟,问题解决了!
await bucket
.upload(filePath, {
destination: key,
gzip: true,
metadata: {
cacheControl: "public, max-age=60" // 1 minute caching
},
public: true
});https://stackoverflow.com/questions/67690715
复制相似问题