Report this

What is the reason for this report?

i want to upload image from react js to digitalocean spaces. but it gives cors error.

Posted on October 6, 2024

hello.

from react js i want to upload image directly to the digitalocean spaces without any server.

the frontend run on localhost 5173 port. and i already configured the cors for this port.

but its still gives me this issue.

here is my code

image alt text

cors configuration: image alt text



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

I think the CORS issue might be related to how Spaces handles the preflight OPTIONS request when you’re uploading directly from the browser. From what I understand, you don’t actually set OPTIONS explicitly in the Spaces CORS settings, it’s handled automatically if the real method you’re calling (like PUT or POST) is allowed.

A few things I’d still double‑check:

  • Make sure the Allowed Methods list in Spaces includes the method you’re using for the upload (PUT or POST).

  • Confirm the origin (http://localhost:5173) is added to the Allowed Origins.

  • If you’re sending custom headers (like Authorization or Content-Type), make sure they’re in Allowed Headers.

If those look fine, it might help to inspect the network tab in your browser’s dev tools to see exactly what headers the preflight request is sending and what the response from Spaces includes.

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.