Created
January 9, 2020 15:09
-
-
Save grant/62edeae5ffdb5f6ca328209f54f948ab to your computer and use it in GitHub Desktop.
Cloud Run Storage – Cloud Storage
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
// 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