Is there any way to set Bucket\'s default cache control (trying to override the public, max-age=3600 in bucket level every time creating a new object)
S
I know that this is quite an old question and you're after a default action (which I'm not sure exists), but the below worked for me on a recent PHP project after much frustration:
$object = $bucket->upload($tempFile, [
'predefinedAcl' => "PUBLICREAD",
'name' => $destination,
'metadata' => [
'cacheControl' => 'Cache-Control: private, max-age=0, no-transform',
]
]);
Same can be applied in node:
const storage = new Storage();
const bucket = storage.bucket(BUCKET_NAME);
const blob = bucket.file(FILE_NAME);
const uploadProgress = new Promise((resolve, reject) => {
const blobStream = blob.createWriteStream();
blobStream.on('error', err => {
reject(err);
throw new Error(err);
});
blobStream.on('finish', () => {
resolve();
});
blobStream.end(file.buffer);
});
await uploadProgress;
if (isPublic) {
await blob.makePublic();
}
blob.setMetadata({ cacheControl: 'public, max-age=31536000' });