CORS is still getting error

Continuing the discussion from CORS error when using Direct Creator Upload:

1 Like

@zaid @yevgen I saw previous posts concerning this problem, you wrote that you’ve fixed the issue but I’m still experiencing it. Maybe I’m doing something wrong. Please let me know ASAP. Trying to upload image from http://localhost using JS axios according with documentation:

const apiUrl = `https://api.cloudflare.com/client/v4/accounts/${process.env.cdnAccountId}/images/v1/direct_upload`
const formData = new FormData()
          formData.append('file', file)
          axios
            .post(apiUrl, formData, {
              headers: {
                'Content-Type': 'multipart/form-data',
                Authorization: `Bearer ${process.env.cdnToken}`,
              },
            })

but browser gives me an error:

Access to XMLHttpRequest at ‘https://api.cloudflare.com/client/v4/accounts/6fc232b74b51f1028fef57c23bf4e87f/images/v1/direct_upload’ from origin ‘http://localhost:3000’ 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.

This topic was automatically closed after 15 days. New replies are no longer allowed.

Continuing the discussion from CORS is still getting error:

Tried multiple way to ask for helping with CORS, I made a workaround by using Cloudflare worker to pass this CORS error but it definitely not the best way for using Cloudflare Image

How are you uploading images? None of their API calls have CORS headers because you should not be uploading straight from the browser.

After I posted this post, my upload api is getting this CORS error, I tried upload from browse. So do you mean I have to send the image to backend, then after that it will be uploaded to Cloudflare?
I just want to upload the image like presigned url from AWS S3

@ethan_ltu which API are you using? Only the URLs generated by the direct upload API has CORS, the direct_upload API itself shouldn’t be called from a browser.

2 Likes

So can you suggest me another option to upload an image to Cloudflare from browser? Cause it’s not the case, I don’t know how to upload. AWS S3 allows me to upload from browser and it is very convenient. One more thing, I just got this CORS from Direct Creator Upload from yesterday, before that, everything worked fine.
Also this post about CORS, I said I tried to fetch() image to put into a canvas, but it showed me the same error. I think other people also have the same error like me

To confirm, I am using this API as the document said

I found this issue from couple of months ago, @zaid @yevgen said it fixed but now this CORS error comes up again. I am trying to migrate from S3 to Cloudflare Image

I confirm someone has fixed this, I can upload to Cloudflare via Direct Upload from my browser, but yesterday it didn’t work. Waiting someone to confirm it stable from now on, then this issue can be closed, thank you!