Not able to retrieve images from a folder.

Harshit_2004
Harshit_2004 Member Posts: 1
edited June 14 in Developer APIs

The images in this folder do not reflect their containing folder's name in their public id as they were moved there in Dynamic folder mode, as a result when i try to fetch all the photos a that folder it results null.

CODE:

const fetchMediaFromFolder = async (folderPath) => {  try {    const result = await cloudinary.api.resources({      type: 'upload',      prefix: folderPath,      resource_type: 'image',     });    return result.resources;  } catch (error) {    throw new Error('Error fetching media from folder: ' + error.message);  }};

This results Null on fetchMediaFromFolder('Tarang "23') even though it have multiple images.

Tagged:

Answers

  • greg13
    greg13 Member Posts: 1

    have you tried resources_by_asset_folder? not sure but it might work
    https://cloudinary.com/documentation/admin_api#get_resources_by_asset_folder

    const fetchMediaFromFolder = async (folderPath) => {
    try {
    const result = await cloudinary.api.resources_by_asset_folder({
    asset_folder: folderPath,
    resource_type: 'image',
    });
    return result.resources;
    } catch (error) {
    throw new Error('Error fetching media from folder: ' + error.message);
    }
    };

    fetchMediaFromFolder('Tarang "23"');

  • Vdeub
    Vdeub Member, Cloudinary Staff Posts: 78

    Hi @Harshit_2004,

    I see you deleted all the folders. When looking at our logs, it seems it was the format of the text you were passing as we were raising the following error:

    AppException: Query Error (at position 18) 'folder=Tarang "23 ➥➥➥'
    

    Happy to investigate further if you recreate the folder.

    Best,

    Loic