Api 改变,使用:
var gcloud = require('gcloud')({
projectId: 'your_id',
keyFilename: 'your_path'
});
var storage = gcloud.storage();
var bucket = storage.bucket('bucket_name');
bucket.acl.default.add({
entity: 'allUsers',
role: storage.acl.READER_ROLE
}, function(err) {});
要公开整个存储桶,您还可以使用:
bucket.makePublic
来源:https ://github.com/GoogleCloudPlatform/gcloud-node/blob/v0.16.0/lib/storage/bucket.js#L607
或者只是文件:
var bucketFile = bucket.file(filename);
// If you upload a new file, make sure to do this
// in the callback of upload success otherwise it will throw a 404 error
bucketFile.makePublic(function(err) {});
来源:https ://github.com/GoogleCloudPlatform/gcloud-node/blob/v0.16.0/lib/storage/file.js#L1241 (链接可能会改变,makePublic
在源代码中查找。)
或者:
bucketFile.acl.add({
scope: 'allUsers',
role: storage.acl.READER_ROLE
}, function(err, aclObject) {});
这是详细版本。
来源:https ://github.com/GoogleCloudPlatform/gcloud-node/blob/v0.16.0/lib/storage/file.js#L116