简体   繁体   中英

How to fetch all images from cloudinary folder

I want to fetch all the images from a folder in cloudinary. as per the below code i want to return all the data fetched as a response to get post controller but when i make request from my react app it says result is not defined. Please share some logic on how to return all the fetched images

Also need help on how to fetch a single image inside a folder in cloudinary using {id} as param

`    




     import { catchAsyncErr } from "../middleware/catchAsyncErrors.js";
     export const getPosts = catchAsyncErr(async (req, res) => {
     cloudinary.v2.api.resources({
     type: 'upload',
     prefix: '{my_folder_name}' // add your folder
   },
    function(error, result) { console.log(result, error) });
    res.status(200).json({
    success: true,
    result,
   });
  });
   //
   router.route("/posts").get(getPosts)

`

try to put

res.status(200).json({
    success: true,
    result,
      });

inside

function(error, result) { console.log(result, error);
res.status(200).json({
        success: true,
        result,
       });
 })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM