在Excel中创建了一个xlsx文件,通过控制台从桌面手动上传到亚马逊S3。现在我想添加一个端点到javascript express服务,该服务将从S3检索该文件,并将其传递回Node.js浏览器应用程序。
对于纯文本文件似乎没问题,但xlsx文件(甚至是在Excel中创建的csv )的HTTP状态码仍为500。
尝试过的变体,比如:
res.send(s3.getObject().toString()); //this works with plain text file
res.send(s3.getObject().toString('utf-8'));
res.send(s3.getObject().toString('binary'));
这些都不走运,呼叫立即失败,并出现500内部服务器错误。
发布于 2020-11-26 11:27:05
就像这样
s3.headObject(params,
(err, data)=>{
if (err) {
return res.status(500).end(err.message);
}
// Add the content type to the response (it's not propagated from the S3 SDK)
res.set({
'Content-Type': data.ContentType,
'Content-Length': data.ContentLength,
'Last-Modified': data.LastModified,
'ETag': data.ETag
});
s3.getObject(params).createReadStream().pipe(res)
}
);
https://stackoverflow.com/questions/65015445
复制相似问题