Created
May 8, 2015 10:03
-
-
Save y16ra/994f30e6d9d63f07a85c to your computer and use it in GitHub Desktop.
node.jsでGoogle Cloud Strageのファイル操作する例
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
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