Uploading images to cloudinary via Nextjs + React-Hook-Form + Zod

Pedro_Souza
Pedro_Souza Member Posts: 4
edited July 2024 in Tips, Tricks, and Guides

Hi, after resolving a problem with my next app, i decided to make a quick tutorial from what i have done, making it clear that this can be not the best example, its just a test.

I used React-Dropzone to catch values and React-Hook-Form to handle my form (that contains name, description and an optional array of images):

Captura de Tela 2024-05-02 às 01.11.08.png

(i will skip react-dropzone cause its not the actual meaning of this post).

after that, i create a function to recieve the array and send it to Cloudinary:

Captura de Tela 2024-05-02 às 01.16.18.png

I call this function in my react-hook-form submit function (with the help of ZodProvider):

Captura de Tela 2024-05-02 às 01.16.51.png

This function is responsable to make the call from next js project route:

Captura de Tela 2024-05-02 às 01.21.48.png

And this function in the next api:

Captura de Tela 2024-05-02 às 01.19.51.png

Hope you liked this quick tutorial

Comments