Cloudflare Images direct upload CORS error

Hi, I’m having same issue, ref: Cloudflare Images direct upload CORS problem

When I try the example code from the doc, I got the CORS error

Access to fetch at 'https://api.cloudflare.com/client/v4/accounts/x/images/v2/direct_upload' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

code snippet from the API doc https://developers.cloudflare.com/api/operations/cloudflare-images-create-authenticated-direct-upload-url-v-2:

const form = new FormData();
form.append("expiry", "");
form.append("id", "");
form.append("metadata", "");
form.append("requireSignedURLs", "");

const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001',
    Authorization: 'Bearer undefined'
  }
};

options.body = form;

fetch('https://api.cloudflare.com/client/v4/accounts/account_identifier/images/v2/direct_upload', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
1 Like

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