【发布时间】:2022-01-03 22:42:01
【问题描述】:
我正在尝试将图像文件上传到 s3,但收到此错误消息:
ERROR: MethodNotAllowed: The specified method is not allowed against this resource.
我的代码使用@aws-sdk/client-s3 包上传此代码:
const s3 = new S3({
region: 'us-east-1',
credentials: {
accessKeyId: config.accessKeyId,
secretAccessKey: config.secretAccessKey,
}
});
exports.uploadFile = async options => {
options.internalPath = options.internalPath || (`${config.s3.internalPath + options.moduleName}/`);
options.ACL = options.ACL || 'public-read';
logger.info(`Uploading [${options.path}]`);
const params = {
Bucket: config.s3.bucket,
Body: fs.createReadStream(options.path),
Key: options.internalPath + options.fileName,
ACL: options.ACL
};
try {
const s3Response = await s3.completeMultipartUpload(params);
if (s3Response) {
logger.info(`Done uploading, uploaded to: ${s3Response.Location}`);
return { url: s3Response.Location };
}
} catch (err) {
logger.error(err, 'unable to upload:');
throw err;
}
};
我不确定这个错误是什么意思,一旦文件上传,我需要在 s3 中获取他的位置
感谢您的帮助
【问题讨论】:
标签: amazon-web-services amazon-s3 aws-sdk-js aws-sdk-nodejs