Skip to content

Instantly share code, notes, and snippets.

@grant
Created January 9, 2020 15:09
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 grant/62edeae5ffdb5f6ca328209f54f948ab to your computer and use it in GitHub Desktop.
Save grant/62edeae5ffdb5f6ca328209f54f948ab to your computer and use it in GitHub Desktop.
Cloud Run Storage – Cloud Storage
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
async function uploadFile(req, res) {
// Uploads a local file to the bucket
await storage.bucket(res.query.bucket).upload(req.query.filename, {
// Support for HTTP requests made with `Accept-Encoding: gzip`
gzip: true,
// By setting the option `destination`, you can change the name of the
// object you are uploading to a bucket.
metadata: {
// Enable long-lived HTTP caching headers
// Use only if the contents of the file will never change
// (If the contents will change, use cacheControl: 'no-cache')
cacheControl: 'public, max-age=31536000',
},
});
console.log(`${filename} uploaded to ${bucket}.`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment