[英]AWS serverless S3 upload doesn't upload files
I have a AWS serverless app that needs to upload files to S3.我有一个需要将文件上传到 S3 的 AWS 无服务器应用程序。 The files are not uploaded and no error is received.文件没有上传,也没有收到错误。 It's the same result when I run it locally with 'sam local' that has no S3 connection.当我使用没有 S3 连接的“sam local”在本地运行它时,结果相同。 The last line that gets printed is 'logger.debug('Uploading to S3', uploadParams);'打印的最后一行是 'logger.debug('Uploading to S3', uploadParams);' Why do you think no error is received?为什么你认为没有收到错误?
async function uploadFileToS3 (fileAttributes) {
// call S3 to retrieve upload file to specified bucket
const uploadParams = { Bucket: bucket, Key: '', Body: '' };
const fileStream = fs.createReadStream(fileAttributes.filepath);
fileStream.on('error', (err) => {
logger.error('File Error', err);
});
uploadParams.Body = fileStream;
uploadParams.Key = fileAttributes.filename;
logger.debug('Uploading to S3', uploadParams);
// call S3 to retrieve upload file to specified bucket
try {
const stored = await s3.upload(uploadParams).promise();
logger.info('Upload Success', stored);
} catch (err) {
logger.error('S3 upload error', err);
}
}
The issue was that the uploadFileToS3 was called in a forEach loop which is not promise aware.问题是uploadFileToS3 是在不支持promise 的forEach 循环中调用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.