简体   繁体   English

如何从 cloudinary 文件夹中获取所有图像

[英]How to fetch all images from cloudinary folder

I want to fetch all the images from a folder in cloudinary.我想从 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.根据下面的代码,我想返回所有获取的数据作为响应以获取帖子 controller 但是当我从我的反应应用程序发出请求时,它说结果未定义。 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还需要有关如何使用 {id} 作为参数在 cloudinary 中的文件夹中获取单个图像的帮助

`    




     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,
       });
 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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