admin管理员组文章数量:1128305
I am trying to display images stored in s3 in my react application . I can upload the file in s3 and see it in my bucket with the preSignedUrl. While rendering the images in react, i keep on getting an error with the preSignedUrl which i generate in my server (Nodejs) application.
Here's the code snippet.
Server side code to download the image from S3.
const client = new S3Client({ region: aws.region });
const command = new GetObjectCommand({
Bucket: aws.bucketName,
Key: imageName,
});
let presignedURL = await getSignedUrl(client, command, { expiresIn: 3600 });
This return's me the preSignedurU which i pass it to the frontend and try to display the same in an img tag in react.
<img
src="presignedURLGetObjct"
className="img-fluid rounded-start"
alt="..."
/>
In the Network tab i keep on getting this error while the request gets a status 200.
Network tab
I have created a IAM user and added the polies as below.
IAM User policy
My Bucket policy and CORS settings looks something like this.
AWS Bucket Policy
AWS CORS settings
While i check with the preSignedURL in browser i get this response.
preSignedURL Response
I am also providing the upload image code to S3 for the server side. Server side upload code.
const secret = "secret";
const hash = createHmac("sha512", secret).digest("hex");
const imageName = "gucci2.jpg";
const s3Client = new S3Client({
accessKeyId: aws.accessKeyId,
secretAccessKey: aws.secretAccessKey,
region: aws.region,
});
const command = new PutObjectCommand({
Bucket: aws.bucketName,
Key: imageName,
// Expires: 60,
// ChecksumSHA256: hash,
});
const presigned = await getSignedUrl(s3Client, command, {
expiresIn: 3600,
// signableHeaders: new Set(["content-type"]),
// Set of all x-amz-* headers you wish to have signed
// unhoistableHeaders: new Set(["x-amz-checksum-sha256"]),
});
Any leads would be appreciated.
本文标签: nodejsDisplaying images stored in AWS v3 s3 in reactjsStack Overflow
版权声明:本文标题:node.js - Displaying images stored in AWS v3 s3 in reactjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736718801a1949350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论