Instantly share code, notes, and snippets.

Embed
What would you like to do?
node.jsでGoogle Cloud Strageのファイル操作する例
var projectId = process.env.GCLOUD_PROJECT_ID
var gcloud = require('gcloud')({
projectId: projectId,
keyFilename: '/local/path/to/keyfile'
});
var storage = gcloud.storage();
var bucket = storage.bucket('storageName');
var options = {
destination: '2015/05/file',
validation: 'crc32c'
}
bucket.upload("/local/path/to/file", options, function(err, file){
if (err) {
console.log("err: " + err);
} else if (!file) {
console.log("empty");
} else {
console.log("ok");
bucket.getFiles(function (err, files, nextQuery, resp) {
console.log("get files");
files.forEach(function(file){
console.log("file name: " + file.name);
file.makePublic(function(err, resp){
console.log(err);
});
});
console.log("done.");
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment