Skip to content

Instantly share code, notes, and snippets.

@y16ra
Created May 8, 2015 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y16ra/994f30e6d9d63f07a85c to your computer and use it in GitHub Desktop.
Save y16ra/994f30e6d9d63f07a85c to your computer and use it in GitHub Desktop.
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