Next.js Discord

Discord Forum

Issue after uploading image to AWS S3

Unanswered
West African Crocodile posted this in #help-forum
Open in Discord
Avatar
West African CrocodileOP
I've used several ways to upload images to aws with NextJS, but whenever I tried to access the created URL I get the message Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4.

import { S3, PutObjectCommand } from '@aws-sdk/client-s3';

const creds = {
    accessKeyId: "****************",
    secretAccessKey: "****************",
};

const S3Client = new S3({
    apiVersion: '2006-03-01',
    region: 'us-east-2',
    credentials: creds,
})
    const [image, setImage] = useState<File | null>(null);

    const addImage = (e: ChangeEvent<HTMLInputElement>) => {
        e.preventDefault();
        const file = e.target.files?.[0]!;

        if (!file) {
            return ;
        };

        setImage(file);
    };

    const uploadImage: MouseEventHandler<HTMLButtonElement> = async (e) => {
        e.preventDefault();
        if (!image) {
            return ;
        };

        const input = {
            Bucket:'******',
            Key: image.name,
            Body: image,
        }

        const command = new PutObjectCommand(input);
        const response = await S3Client.send(command);
    }

I recieve the message from console log when it succeeds uploading but I cannot seem to understand what's missing in my code, as you can see it's pretty simple.
Image

0 Replies