Created
February 3, 2020 04:35
-
-
Save alexander-elgin/01e08b79de3b880062c53e803d768699 to your computer and use it in GitHub Desktop.
Upload File to Google Cloud Storage
This file contains hidden or 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'); | |
const storage = new Storage({ | |
projectId: 'akbarserver', | |
keyFilename: './service-account.json' | |
}); | |
function uploadFile(filename, bucketName) { | |
return storage.bucket(bucketName).upload(filename, { | |
gzip: true, | |
metadata: { | |
cacheControl: 'public, max-age=31536000', | |
}, | |
}); | |
} | |
uploadFile('./test.txt', 'test-bucket-akbar').then(console.log).catch(console.error); |
Author
alexander-elgin
commented
Feb 3, 2020
service-account.json
file can be generated in the Credentials section
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment