Skip to content

Instantly share code, notes, and snippets.

@alexander-elgin
Created February 3, 2020 04:35
Show Gist options
  • Save alexander-elgin/01e08b79de3b880062c53e803d768699 to your computer and use it in GitHub Desktop.
Save alexander-elgin/01e08b79de3b880062c53e803d768699 to your computer and use it in GitHub Desktop.
Upload File to Google Cloud Storage
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);
@alexander-elgin
Copy link
Author

yarn add @google-cloud/storage

@alexander-elgin
Copy link
Author

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