Last active
February 24, 2018 04:11
-
-
Save justinph/acb6301d63b407e1fb205cbb42e08cba to your computer and use it in GitHub Desktop.
gcs set meta on upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "set-the-meta", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "justinph <[email protected]>", | |
"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