Skip to content

Instantly share code, notes, and snippets.

@justinph
Last active February 24, 2018 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinph/acb6301d63b407e1fb205cbb42e08cba to your computer and use it in GitHub Desktop.
Save justinph/acb6301d63b407e1fb205cbb42e08cba to your computer and use it in GitHub Desktop.
gcs set meta on upload
const storage = require('@google-cloud/storage')();
exports.setMeta = function (event, doneCb) {
const file = event.data;
const gcsBucket = storage.bucket(file.bucket);
const gcsFile = gcsBucket.file(file.name);
if (file.metageneration === '1') {
return gcsFile
.setMetadata({
cacheControl: 'public, maxage=3600',
})
.then(() => {
doneCb();
})
.catch((e) => {
console.error(`Error, metadata not set on ${file.name}.`, e);
});
} else {
doneCb();
}
};
{
"name": "set-the-meta",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "justinph <justin@fiddlyio.com>",
"license": "ISC",
"dependencies": {
"@google-cloud/storage": "^1.5.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment