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
cors configuration:
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!
Hi there,
The CORS preflight requests are often sent using the OPTIONS
method, especially when performing a POST or PUT request from a browser. Make sure your CORS settings allow the OPTIONS
method. You can add OPTIONS
to your allowed methods in the DigitalOcean Spaces CORS configuration:
Allowed Methods: GET, PUT, DELETE, HEAD, POST, OPTIONS
Also check that you’re setting the correct headers in your request, especially Content-Type
. Sometimes, a missing or incorrect Content-Type
can trigger CORS issues.
In your case, you already have the content type set in the params
:
ContentType: file.type
Besides that, make sure that the file type is correctly detected. If needed, explicitly set it to multipart/form-data
in case of issues:
ContentType: "multipart/form-data",
You can also use your browser’s developer tools to see what the CORS preflight request (OPTIONS
) and response look like. Check if the headers on the response allow the origin, methods, and other necessary headers.
Make sure that your CORS settings on DigitalOcean Spaces allow the following headers:
Access-Control-Allow-Origin
: *
or the specific origins (http://localhost:5173
)Access-Control-Allow-Methods
: Ensure GET
, PUT
, POST
, and OPTIONS
are allowedAccess-Control-Allow-Headers
: If you’re sending custom headers, such as Authorization
or Content-Type
, make sure they are allowed here as well.Once you’ve made these changes, try again, and let me know if the issue persists!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.