Node.js 谷歌云功能-读取使用NodeJS创建的bucket新文件的内容

Node.js 谷歌云功能-读取使用NodeJS创建的bucket新文件的内容,node.js,function,google-cloud-functions,google-cloud-storage,bucket,Node.js,Function,Google Cloud Functions,Google Cloud Storage,Bucket,在GCP(不是firebase)中,我有一个bucket和一个函数,在bucket中创建新文件时将调用该函数。效果很好 /** * Triggered from a change to a Cloud Storage bucket. */ exports.mycompany_upload_file = (event, context) => { const gcsEvent = event; const filename = gcsEvent.name; con

在GCP(不是firebase)中,我有一个bucket和一个函数,在bucket中创建新文件时将调用该函数。效果很好

/**
 * Triggered from a change to a Cloud Storage bucket.
 */
exports.mycompany_upload_file = (event, context) => {
    const gcsEvent = event;
    const filename = gcsEvent.name;
    const bucketName = event.bucket;
    console.log(`=====================================================`);
    console.log(`Event Type: ${context.eventType}`);
    console.log(`Bucket:     ${bucketName}`);
    console.log(`Datei:      ${filename}`);
    console.log(`=====================================================`);

    // now I would like to open that file and read it line-by-line 
我该如何处理该文件?那个文件的路径是什么? 我可以使用像“fs”这样的标准节点库吗?

我发现这可能对您有所帮助,但看起来基本上答案如下:

请注意,它将结果存储在ramdisk中,因此您需要足够的RAM来下载该文件

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();}
  })
};
var storage=require(“@googlecloud/storage”);
const gcs=存储({projectId:“});
const bucket=gcs.bucket(“”);
常量文件=bucket.file(“”)
exports.gcstest=(事件,回调)=>{
下载({destination:“/tmp/test”},函数(err,file){
if(err){console.log(err)}
else{callback();}
})
};
要了解更多信息,您可以查看文档,我发现这可能会对您有所帮助,但基本上答案如下:

请注意,它将结果存储在ramdisk中,因此您需要足够的RAM来下载该文件

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();}
  })
};
var storage=require(“@googlecloud/storage”);
const gcs=存储({projectId:“});
const bucket=gcs.bucket(“”);
常量文件=bucket.file(“”)
exports.gcstest=(事件,回调)=>{
下载({destination:“/tmp/test”},函数(err,file){
if(err){console.log(err)}
else{callback();}
})
};

要了解更多信息,您可以查看文档

我希望有一种方法可以直接读取存储桶中的文件,而无需复制到(ram)磁盘。任何处理都必须在ram中完成,云存储不是执行计算的解决方案,我希望有一种方法可以直接读取bucket中的文件,而无需复制到(ram)磁盘。任何处理都必须在ram中的某个地方完成,云存储不是执行计算的解决方案,如果你检查了它,它不包括处理。