Created
April 15, 2014 13:59
-
-
Save onlinemad/10735051 to your computer and use it in GitHub Desktop.
Sample of upload file to Google Cloud Stoage.
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
/** | |
* 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