leerob / nextjs-aws-s3

Example Next.js app to upload photos to an S3 bucket.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CORS issues on formData post

Trennel opened this issue · comments

Hi there,

First of all thanks for your example. It's really helpful.

I'm always getting CORS issues for this piece of code:

    const upload = await fetch(url, {
      method: 'POST',
      body: formData,
    });

Are there any specific nextJS settings I need to add for this to work?
If i move this piece of code to pages/api everything works without errors.
However the data gets submitted to my S3 bucket whilst throwing a CORS error.

Any help on this?

Thanks alot!

Make sure you follow the instructions in the README and apply the correct CORS settings 👍

https://github.com/leerob/nextjs-aws-s3/blob/main/lib/hello-cdk-stack.js#L13-L19

@leerob
Same issue
has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
S3 has been initialised by following instructions in the repo.

UPD: seems solved by .withCredentials = false