1 comment

  • Official comment
    Danny Valentine

    Hi Henry.

    Without knowing a bit more about your code and environment it's difficult to pinpoint why you might be getting CORS errors. I'm not sure if you're using Express, but if you are, this middleware may help:

    As for the request itself, you need to specify Basic auth as base64 encoded. I've tried this locally and it has returned a 200 in my testing. I've used dotenv instead of calling environment variables directly as I find this a bit more reliable.

    const fetch = require('node-fetch');

    const ENDPOINT_FETCH_ALL = '' + process.env.CLOUD_NAME + '/resources/image';


    async function fetchImagesInCloudinary() {
    let images = [];
    let headers = new fetch.Headers();

    headers.set('Authorization', 'Basic ' + Buffer.from(process.env.API_KEY + ":" + process.env.API_SECRET).toString('base64'));

    const response = await fetch(ENDPOINT_FETCH_ALL, {
    method: "GET",
    headers: headers

    console.log({ response });

    return images;

    Give that a try and let us know how you get on. Ultimately though, it may be easier to use our Node SDK as that greatly simplifies connecting to a cloud, fetching assets, and much much more.

    Kind regards,

    Comment actions Permalink

Please sign in to leave a comment.