我正在创建一个解决方案,其中文件和表单数据从html-form提交到Api网关,然后提交到AWS lambda进行处理,这些数据可以是“metapart / form-data”或“application / x-www” -form-urlencoded“以及我的Api网关二进制支持已经配置。我用谷歌搜索但无法找到哪个node.js库用于解析标题Content-type.Below是我正在使用的代码:
enter code here
const AWS = require('aws-sdk');
var s3 = new AWS.S3({apiVersion: '2006-03-01'});
const querystring = require('querystring');
AWS.config.region = 'xxx';
// "exports.handler" must match the entrypoint defined in the lambda Config.
exports.handler = function (event, context, callback) {
var bodyBuffer = new Buffer (String(event ['body-json']),'base64');
const params1 = querystring.parse(event.body);
var param = {Bucket:'mybucket', Key:'abc.csv', Body: bodyBuffer};
console.log("s3");
s3.upload(param, function(err, bodyBuffer) {
if (err) {
console.log(err, err.stack); // an error occurred
}
else console.log(bodyBuffer); // successful response
console.log('actually done!');
context.done();
});
const my_field1 = params1['my-field1'];
const html = `<!DOCTYPE html><p>You said: ` + my_field1 + `</p>`;
if(my_field1==''){
callback (null, "textfield1Notfilled");
}
callback(null, html);
}
(现在这段代码将文件上传到S3存储桶并在html页面上显示formdata) 请帮忙!!
答案 0 :(得分:0)
您可以尝试使用event.headers
获取所有请求标头,然后使用event.headers['Content-Type'
]。