【发布时间】:2016-12-14 23:20:04
【问题描述】:
更新谷歌云存储桶中的图片时,即使图片更新成功,url也会服务旧版本一段时间(几分钟,例如5分钟左右)。
我们使用的链接如下:
https://storage.googleapis.com/<bucket-name>/path/to/images/1.jpg
更新图像的代码的相关部分是:
var storageFile = bucket.file(imageToUpdatePath);
var storageFileStream = storageFile.createWriteStream({
metadata: {
contentType: req.file.mimetype
}
});
storageFileStream.on('error', function(err) {
...
});
storageFileStream.on('finish', function() {
// cloudFile.makePublic after the upload has finished, because otherwise the file is only accessible to the owner:
storageFile.makePublic(function(err, data) {
//if(err)
//console.log(err);
if (err) {
return res.render("error", {
err: err
});
}
...
});
});
fs.createReadStream(filePath).pipe(storageFileStream);
这看起来像是 Google Cloud 端的缓存问题。如何解决?更新后如何在请求的url获取更新的图片?
在 Google Cloud 管理员中,新图像确实正确显示。
【问题讨论】:
标签: javascript node.js caching google-cloud-storage