How to get all images from cloudinary and display them in my web page ?

Comments

3 comments

  • Avatar
    Loic Verger Del Bove

    Hi,

    You should be able to do this by using the Search API to list all the images URL in your `LostDocs` folder and then display it on your second page. Here is a script that will list all the URLs and put them in an array:

    var result = [];

    var options = { resource_type:"image", folder:"your_folder", max_results: 500};

    function listResources(next_cursor) {
    if(next_cursor) {
    options["next_cursor"] = next_cursor;
    }
    console.log(options);
    cloudinary.api.resources(options, function(error,res){
    if (error) {
    console.log(error);
    }
    var more = res.next_cursor;
    resources = res.resources;

    for(var res in resources) {
    res = resources[res];
    var resultTemp = [];
    var url = res.secure_url;
    resultTemp.push(url);
    result.push(resultTemp);
    }

    if (more) {listResources(more);}
    else {console.log("done");}
    });
    }
    listResources(null);

    Best,

    Loic

    1
    Comment actions Permalink
  • Avatar
    yuoenss assrear

    Thank you for answering my question !

    Now, how can i integrate those results into my html page ? Do i have to use a template engine like ejs ?

    the script you provided works fine but only answer my question partly.

    thanks again 

    0
    Comment actions Permalink
  • Avatar
    Loic Verger Del Bove

    Hi there,

    Since you have the list of URL on the backend, you can now either use a template engine (on my side I use pug) or not to render the images but in any case, you will need to loop through this list and create an `img` element for each URL. 

    Hope that helps.

    Best,

    Loic

    0
    Comment actions Permalink

Please sign in to leave a comment.