CORS Error when fetching folders in browser
I'm trying to make a request to fetch the folders in my cloudinary account from my browser but I get this CORS error:
Access to fetch at 'https://api.cloudinary.com/v1_1/<cloudinary_name>/folders' from origin 'http://localhost:3002' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
This is my code:
I have tried using the NodeJS SDK to make this request but it seems that does not work for me in the browser environment.
Is there anything else I can try?
Any help would be appreciated. Thanks
-
Hi Rotimi,
As a general issue, making CORS requests from localhost will not work in many cases because web services often expect that requests are being made from a fully qualified domain name.
For this specific example, it's not supported or recommend to call our Admin API methods from frontend code, and our Node SDK is not intended for use in frontend code either and will likely be missing dependencies that are expected to be present in a Node server but won't be present in frontend code.
It's not possible to call Admin API methods safely from frontend code because they require authentication using your account's API Secret, and doing so leaves your account vulnerable and allows your users to make arbitrary API calls to the account.
It's also difficult to call Upload API methods from frontend code unless you have a server-side endpoint providing the necessary signature for Upload API calls (and in that case, it's easier to call the API from the server-side and pass the results to your frontend)
For this example, I recommend that you keep your own database of assets on the server side and use that to populate your frontend, or add a mechanism where your frontend code asks your server to make the API call and then pass the result to your frontend
Regards,
Stephen
0
Post is closed for comments.
Comments
1 comment