[英]Amazon S3 Fetching Error: "NoSuchKey" However Key Does Exist
I am trying to fetch a S3 Object using AWS Storage我正在尝试使用 AWS 存储获取 S3 Object
fetchAvatar = async () => { try { const imageData = await Storage.get("public/public/us-east-2:/1597842961073/family.jpg") console.log(imageData) } catch (err) { console.log('error fetching avatar: ') console.log(err) } }
When I click on the link that the imageData provides I get NoSuchKey error, however it does exist当我单击 imageData 提供的链接时,出现 NoSuchKey 错误,但它确实存在
I've made sure that the image is public and accessible by everyone, so there shouldn't be any authentication problems.我已经确保图像是公开的并且每个人都可以访问,因此不应该有任何身份验证问题。 I've also looked at similar issue to this and I made sure there is no spaces or a lot of special keys in my image keys.我也研究过与此类似的问题,并确保我的图像键中没有空格或很多特殊键。 I am kind of stumped on this...我有点被这个难住了...
So I figured out the reason, and it has to do something with AWS S3 Management.所以我弄清楚了原因,它必须与 AWS S3 Management 做一些事情。 For some reason that every time I upload an image, the folder will reset and become privet.由于某种原因,每次我上传图片时,文件夹都会重置并变成女贞。 When I remake the folders and image public manually I am able to render the image properly...So i guess it is more of AWS issue or bug that they need to fix I think当我手动重新制作文件夹和公开图像时,我能够正确渲染图像......所以我想他们需要修复的更多是 AWS 问题或错误我认为
I suggest to usejavascript aws sdk , you can get an object from the bucket like below:我建议使用javascript aws sdk ,你可以从下面的桶中得到一个 object :
var params = {
Bucket: "your-bucket-name",
Key: "yourFileName.jpg"
};
s3.getObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data);
});
UPDATE:更新:
You can define your region when you create a s3 instance, like:您可以在创建 s3 实例时定义您的区域,例如:
const s3 = new S3({
region: 'eu-central-1',
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.