permission to access metadata!

wikioki
wikioki Member Posts: 3
edited November 13 in Developer APIs

I get this error in my server side code;
appreciate any help!

Error fetching image metadata: Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.


Best Answer

  • DannyFromCloudinary
    DannyFromCloudinary Member, Cloudinary Staff Posts: 150
    Answer ✓

    Hi @wikioki. We don't recommend querying the Admin API on page load because you can very quickly burn through your rate limit. Instead, a better solution may be to pull the info for your assets on a less frequent, but regular basis, and store them in a local database. Then when you need to access the matadata, you can query your database instead.

    I hope this helps!

    -Danny

Answers

  • wikioki
    wikioki Member Posts: 3
    edited November 8

    here is the code
    // app/fetchaction.ts
    "use server";

    import { v2 as cloudinary } from 'cloudinary';

    export interface ImageMetadata {
    public_id: string;
    format: string;
    version: number;
    resource_type: string;
    type: string;
    created_at: string;
    bytes: number;
    width: number;
    height: number;
    folder: string;
    url: string;
    secure_url: string;
    metadata: Record<string, any>;
    }

    export async function fetchImageMetadata(): Promise<ImageMetadata> {
    cloudinary.config({
    cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
    api_key: process.env.NEXT_PUBLIC_CLOUDINARY_API_KEY,
    api_secret: process.env.CLOUDINARY_API_SECRET,
    });

    try {
    const result = await cloudinary.api.resource("ip/remix/2_1731025186094", {
    resource_type: 'image',
    type: 'upload',
    max_results: 1,
    });
    return result as ImageMetadata;
    } catch (error) {
    console.error("Error fetching image metadata:", error);
    throw error;
    }
    }

  • Cloudinary Team
    Cloudinary Team Administrator, Cloudinary Staff Posts: 170 admin

    Hi there,

    Thanks for reaching out. I'm glad you got it sorted and thanks for sharing your solution, so that others may learn as well 😊

    Kind regards,

    Tia
    Developer Support Engineer
    Cloudinary


    🧑‍🎓 Academy Training | 📖 Documentation | 📰 Blog

  • wikioki
    wikioki Member Posts: 3
    edited November 9

    looks like it's API call limit!
    The solution is to optimize the code to lower the amount of API calls.