NodeJS gcloud-使用公共​​读取属性/自定义缓存过期上传到Google存储 [英] NodeJS gcloud - Upload to google storage with public-read property/custom cache-expire

查看:138
本文介绍了NodeJS gcloud-使用公共​​读取属性/自定义缓存过期上传到Google存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gcloud库(NodeJS)上传到Google存储.

I am trying to upload to google storage using the gcloud library (NodeJS).

我需要启用公共读取属性,并将缓存过期时间设置为5分钟.

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) 

如何设置适当的ACL/缓存过期? (我发现了这个,但不知道该怎么做: https://googlecloudplatform.github.io/gcloud -node/#/docs/v0.11.0/storage?method = acl )

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)

感谢您的帮助

推荐答案

您可以按照

关于缓存控制,我不认为您可以将其设置为默认值,但是可以在上传文件时进行设置:

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)

参考: https://cloud.google.com/storage/docs/reference-headers#cachecontrol

这篇关于NodeJS gcloud-使用公共​​读取属性/自定义缓存过期上传到Google存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆