Fetching Array of Images from Cloudinary

Comments

5 comments

  • Avatar
    Raya Straus

    Using the Admin API to list resources on our node SDK is a good option- https://cloudinary.com/documentation/admin_api#list_resources

    Please note that this is not available client side since it means exposing your API secret. That being said, you can use list to list all images with a specific tag.

    For example, 

    http://res.cloudinary.com/<cloud_name>/image/list/<tag_name>.json

    Please take a look at this tutorial for more information and pointers- https://github.com/cloudinary-developers/build-a-mini-netflix/blob/master/React/display-videos.md

    0
    Comment actions Permalink
  • Avatar
    Arbortree Creations

    Hi Raya Straus

    So what your saying is if we want a JSON list of all images such as in my folder called "library", it has to be done through the server, can just get all these from the client. Currently, we do get them from the server. I was just trying to cut away the middle man (Server) ?

    When I try you request endpoint above using axios(http://res.cloudinary.com/<cloud_name>/image/list/<tag_name>.json), it throws unauthorized code 401 ?

    Daniel

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Daniel,

    Most likely the reason you're seeing a 401 error is that by default these client side based resource lists are restricted within accounts. To enable access to those, please log into your account and go to the Settings => Security tab. There you will find a list of different media types, private, upload, fetch in addition to resource lists. If the option next to a type is ticked then this type won't be allowed in the account and thus if you uncheck it, save and retry, it should work for you.

    Apart from resource lists, you'll need to use the API to list resources and this is due to it requiring authentication (API secret to generate the signature) which can't be used on the client side. A solution that may work for you so that you can use resource lists to get images in specific folders is if you also give a tag with the same folder name to assets you put in different folders. That way you can then request resource lists for your images based on the tags which will reflect the folder name.

    Best regards,

    Aleksandar

    0
    Comment actions Permalink
  • Avatar
    Arbortree Creations

    Hi Aleksandar Kostadinov

    Ok, I understand. I'll give that a shot!

    Curious question. We have many client process variables usually saved like so REACT_APP_MY_VARIABLE_NAME. React script auto places these in the process env on the client. Are all these variables public? Can we simply just not hide sensitive variables on the client? Thanks

    Daniel

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Daniel,

    When storing credentials on the client side they are never really hidden, at best, they can be more difficult to obtain. This is why we recommend keeping the API Secret strictly on the server-side, as having access to this can authorize a user to perform actions on your account via the API on your behalf. The API Key, on the other hand, is not sensitive as it won't allow any access on its own and in fact, is part of some client-side code such as when configuring the Media Library Widget.

    Best regards,

    Aleksandar

    0
    Comment actions Permalink

Please sign in to leave a comment.