云功能可以从云存储读取吗? [英] Can a Cloud Function read from Cloud Storage?
问题描述
我可以找到的有关使用GCF + GCS的唯一文档是 https://cloud.google.com/functions/docs/tutorials/storage .AFAICT只是在展示如何使用GCS事件触发GCF.
The only docs I can find about using GCF+GCS is https://cloud.google.com/functions/docs/tutorials/storage. AFAICT this is just showing how to use GCS events to trigger GCF.
在 GCF依赖项的文档中,它仅提及节点模块.GCF代码是否可以从GCS存储桶中读取?是否只是需要一个知道如何与GCS通信的节点模块的情况?如果是,是否有任何示例?
In the docs for GCF dependencies, it only mentions node modules. Is it possible for GCF code to read from a GCS bucket? Is it simply the case of requiring a node module that knows how to communicate with GCS and if so, are there any examples of that?
推荐答案
是的,但是请注意,它将结果存储在ramdisk中,因此您需要足够的RAM可供函数下载文件.
Yes, but note that it will store the result in a ramdisk, so you'll need enough RAM available to your function to download the file.
var storage = require('@google-cloud/storage');
const gcs = storage({projectId: "<your_project>"});
const bucket = gcs.bucket("<your_bucket>");
const file = bucket.file("<path/to/your_file>")
exports.gcstest = (event, callback) => {
file.download({destination:"/tmp/test"}, function(err, file) {
if (err) {console.log(err)}
else{callback();}
})
};
这篇关于云功能可以从云存储读取吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!