我正在尝试将一张图片上传到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中的位置。
感谢任何帮助。
upload()
函数文档的链接:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property - Mark Baws-sdk
包可以工作,但是使用@aws-sdk/client-s3
包时它没有上传功能。 - spinkeraws-sdk
包时,我没有像以前一样得到response.Location
。 - spinker