Request header field x-access-token is not allowed by Access-Control-Allow-Headers in preflight response. CORS when trying on localhost
I've enabled the unsigned uploading but still getting the CORS error:
Access to XMLHttpRequest at 'https://api.cloudinary.com/v1_1/{cloudName}/image/upload' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field x-access-token is not allowed by Access-Control-Allow-Headers in preflight response.
const formData = new FormData();
formData.append('file', attachmentFiles[0]);
formData.append('upload_preset', process.env.REACT_APP_CLOUDINARY_UPLOAD_PRESET);
try {
const result = await Axios.post(
`https://api.cloudinary.com/v1_1/${process.env.REACT_APP_CLOUDINARY_CLOUDNAME}/image/upload`,
formData,
);
console.log(result)
} catch (e) {
console.error(e)
}
-
Hi Dika,
The CORS error is encountered when you try to upload a file from your application's client-side code and the actual upload to your Media Library is done by the server-side implementation of your application. If you wish to upload the images at the client-side of your application, you should consider uploading the file directly from the browser as described in this link: https://cloudinary.com/documentation/upload_images#uploading_with_a_direct_call_to_the_rest_api
Hope this helps.
-
Hi Iswarya,
We are happy to help you review your code and, in this case, could you please help to open a support ticket here (https://support.cloudinary.com/hc/en-us/requests/new) and provide the information about your implementations and the exact error messages you get?
Thanks.
Post is closed for comments.
Comments
8 comments