有没有办法在使用Google Cloud Storage Adapter for Flysystem将文件放入Google Cloud Storage时设置缓存控制元数据?
发布于 2020-10-21 20:39:50
Flysystem具有设置适配器配置的能力。要为GCP存储桶设置缓存控制标头,可以使用next:
/** @var FilesystemInterface $storage */
$storage->put($path, $contents, [
'metadata' => [
'cacheControl' => 'no-cache,max-age=0'
]
]);此外,您还可以在GCP控制台中设置Cloud Function,以便在对象保存到存储桶时设置标头
发布于 2020-09-17 02:16:59
你可以在Set Cache-Control php client on Google Cloud Storage Object的回复中找到一个设置缓存控制的例子。
发布于 2021-02-20 01:02:55
在GSC sonsole上手动编辑
,这是个糟糕的解决方案
gs://yourbucketname/optionalfolder/ -m -D -h缓存控制:“缓存控制:公共,最大年龄=31536000”cp -r gsutil
gs://bucket/*.html -m setmeta -h "Content-Type:text/html“\ -h”缓存控制:公共,最大年龄=3600“\ -h "Content-Disposition”gsutil
域名和灵活的设置。
之后立即设置元(或任何您想要的元
创建包含两个文件index.js和package.json的新文件夹
index.js
enter const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
exports.prepare = (file, context) => {
console.log("prepare: set cache control:" + file.name);
storage.bucket(file.bucket).file(file.name).setMetadata({cacheControl: 'public, max-age=31536000'});
};package.json
{
"dependencies": {
"@google-cloud/storage": ">=5.8.0"
}
}并分两步部署此函数
api deploy(系统会要求先启用
google.storage.object.finalize函数部署准备\--运行时nodejs12 \--触发器资源gs://您的后台名称\--触发器-事件名称
https://stackoverflow.com/questions/63922620
复制相似问题