简体   繁体   English

AWS Lambda:如何在不保存文件的情况下流式传输文件

[英]AWS Lambda: How to stream a file without saving it

I want to run a node function in AWS lambda, and let users upload and analyze their files using a web browser. 我想在AWS lambda中运行节点功能,并允许用户使用Web浏览器上传和分析其文件。 Here is the aforementioned function: 这是上述功能:

analyzer.analyze(fs.createReadStream('./path/to/local/file'),function(err,analysis){
    console.log(JSON.stringify(analysis));
});

As you can see, the first argument of analyzer.analyze method takes a stream. 如您所见,analyzer.analyze方法的第一个参数采用一个流。 How can I create that stream without actually saving the file when running it on AWS lambda? 在AWS Lambda上运行该流时,如何在不实际保存文件的情况下创建该流?

Is there a way to let lambda directly read the file stream from the request, or maybe read the file in memory and then create a stream from there? 有没有办法让lambda直接从请求中读取文件流,或者也许读取内存中的文件,然后从那里创建流?

Are you fine with storing the file in S3? 您可以将文件存储在S3中吗? If yes, you can store the file in S3 and configure the lambda function to trigger upon file creation in that S3 bucket. 如果是,则可以将文件存储在S3中,并将lambda函数配置为在该S3存储桶中创建文件时触发。

The createReadStream requires a file. createReadStream需要一个文件。 The lambda environment has read-only partitions, except the partition /tmp . lambda环境具有只读分区,但分区/tmp除外。 If you just have the createReadStream as option, I'd suggest you to save your file in the /tmp folder instead to upload it in a S3 Bucket. 如果您只有createReadStream作为选项,建议您将文件保存在/tmp文件夹中,而不是将其上传到S3存储桶中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM