小编Tom*_*ula的帖子

Amazon Lambda - 返回 docx 文件 - Node.js

我正在尝试将我的 Node.js 应用程序从Google Cloud Functions迁移到 Amazon Lambda。应用程序从 Amazon S3 加载 docx 文件,对其进行处理并返回该 docx 文件。但是我被困在文件返回的过程中。在 Google Cloud Platform 中,我可以这样做:

module.exports = function(customENV){ return function(req, res) {
    new AWS.S3().getObject({ Bucket: aws_bucket, Key: aws_file }, function(err, data) {
        if(!err) { 
            res.set('Access-Control-Allow-Origin', "*");
            res.set('Access-Control-Allow-Methods', 'GET, POST');
            res.set('Content-Disposition', `inline; filename="rename.docx"`);

            res.type('docx');
            res.status(200);

            res.end(data.Body, 'binary');
        }
    });
}};
Run Code Online (Sandbox Code Playgroud)

在 Amazon Lambda 中,我复制了这样的解决方案:

exports.handler = function(event, context, callback) {
    new AWS.S3().getObject({ Bucket: aws_bucket, Key: aws_file }, function(err, data) {
        if(!err) {
            var response = …
Run Code Online (Sandbox Code Playgroud)

docx amazon-s3 amazon-web-services node.js aws-lambda

4
推荐指数
1
解决办法
2569
查看次数