NodeJS gcloud - 使用公共读取属性/自定义缓存过期上传到谷歌存储 [英] NodeJS gcloud - Upload to google storage with public-read property/custom cache-expire
问题描述
I am trying to upload to google storage using the gcloud library (NodeJS).
I need to enable public-read property and also set the cache-expiration to 5 minutes.
I am using this (simplified) code:
storage = gcloud.storage({options}
bucker = storage.bucket('name');
fs.createReadStream(srcPath).pipe(bucket.file(targetFile).createWriteStream()).on('error', function(err)
How do I go about setting the approprate ACL/cache expire? (I found this but not sure what to make of it: https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.11.0/storage?method=acl)
Thanks for the help
You can set the predefined ACL following the instructions here:
yourBucket.acl.default.add({
entity: "allUsers",
role: gcloud.storage.acl.READER_ROLE
}, function (err) {})
Regarding cache control, I don't believe you can set this as a default, but you can set this at the time of uploading your file:
var opts = { metadata: { cacheControl: "public, max-age=300" } }
bucket.file(targetFile).createWriteStream(opts)
Reference: https://cloud.google.com/storage/docs/reference-headers#cachecontrol
这篇关于NodeJS gcloud - 使用公共读取属性/自定义缓存过期上传到谷歌存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!