Skip to content

Instantly share code, notes, and snippets.

@onlinemad
Created April 15, 2014 13:59
Show Gist options
  • Save onlinemad/10735051 to your computer and use it in GitHub Desktop.
Save onlinemad/10735051 to your computer and use it in GitHub Desktop.
Sample of upload file to Google Cloud Stoage.
/**
* Sample of upload file to Google Cloud Stoage.
*
* 1. Setup a bucket and grant write permission for All Users on Google Cloud Stoage.
*
* 2. Install dependency 'request'
*
* 3. Set 'filename' and 'bucket'
*
* 4. Run!!
*/
var request = require('request'),
fs = require('fs');
var filename = 'filename';
var bucket = 'bucket';
fs.createReadStream(filename).pipe(request.post({
url: 'https://www.googleapis.com/upload/storage/v1beta2/b/' + bucket + '/o?uploadType=media&name=' + filename
}, function(err, res, body) {
if (err) {
console.error('Upload failed:\n', err);
} else {
console.log('Upload successful! Server responded with:\n', body);
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment