upload subfolders

Gersooonn
Gersooonn Member Posts: 2
edited April 30 in Developer APIs

Hi, how are you? It would be a question, I have a product project in NextJs and I wanted to know that I can make each product have its specific mass when it is created. For example:
cellular products/cell01
cellular products/cell02
In this case, it would retrieve the product slug and create the subfolder using the product slug and just the photos of that certain product in that subfolder

Tagged:

Answers

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

    Hi there,

    Thanks for reaching out.

    The upload method of the Upload API accepts a folder parameter. This is the full path of where you want the asset to be uploaded. So if you had a file 'image1.jpg' that you want to upload to the products/cell01 folder, you could include pass folder: 'products/cell01' as part of the options object.
    The other way to go about it would be to include the folder in the public_id parameter. In this case, you would pass public_id: 'products/cell01/image1' as part of the options object.

    Both folder and public_id are optional parameters. You can refer to the following documentation for additional information:
    https://cloudinary.com/documentation/image_upload_api_reference#upload

    I hope this helps. Please give it a try and let us know if you have any questions.

    Kind regards,

    Tia

    Helpful Links For You
    💬 Share questions, connect with other users in our Cloudinary Community forums and Discord server!
    🧑‍🎓 Join our Cloudinary Academy for free courses, workshops and other educational resources.
    📄 Read our documentation for in-depth details on Cloudinary product features and capabilities
    📰 Check out the Cloudinary blog for the latest company news and insights

  • Gersooonn
    Gersooonn Member Posts: 2

    I understand, in fact I would only have the 'products' folder, I wanted the subfolders to be created when the product was created. Creating a subfolder, for example, the slug name is cell01, then it would create a subfolder that would be 'products/cell01'. I'm going to create another product now, product name which would be slug, cell-nokia and then I would create another subfolder with that name. The name of the photo can be random as it is, the important thing is just to be able to separate the photos from each cell phone within its own subfolder.

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

    Hi there,

    You could pass both the folder and public_id parameters to your upload call. The folder could be hard-coded to 'products'. folder:'products' and you could pass the slug name as the first part of the public_id. So if the slug name is cell01 you could use something like:

    cloudinary.uploader.upload(<file here>,{public_id: "cell01/image1",folder: "products",},).then((uploadResult) => console.log(uploadResult)).catch((error) => console.error(error));
    

    The result of the code block above is that the file would be uploaded to your account in the cell01 subfolder of the products folder.

    Let me know if you think that could work for you. If you have any questions, do not hesitate to ask.

    Kind regards,

    Tia

    Helpful Links For You
    💬 Share questions, connect with other users in our Cloudinary Community forums and Discord server!
    🧑‍🎓 Join our Cloudinary Academy for free courses, workshops and other educational resources.
    📄 Read our documentation for in-depth details on Cloudinary product features and capabilities
    📰 Check out the Cloudinary blog for the latest company news and insights