Programmable Media

List images in Next.js (video tutorial)

Last updated: Sep-12-2024

Overview

Learn how to list images using the Next.js app router and the Cloudinary Node.js SDK. Search for assets using queries or by tag, and display them in a Next.js application rendered using React Server Components (RSC).

Video tutorial


Tutorial contents

This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

Introduction

Jump to this spot in the video  0:00 Getting images into Cloudinary is easy but what about getting them out? You can use the Search API and Cloudinary Node.js SDK to display them in your Next.js app router application.

Intro to App router in Next.js

Jump to this spot in the video  0:24 The Next.js app router brings some big changes and improvements to developer experience. The introduction of server vs client components is a key part of this. Client components behave like a typical React component, whereas server components offer the ability to do data fetching from within the component.

Configure Home page for data fetching

Jump to this spot in the video  0:50 By default, pages and components will be server components. You can turn the Home page into an asynchronous component by adding the async tag in front of the function name, making it possible to use await for data fetching.

Add search requests using the Cloudinary Node.js SDK

Jump to this spot in the video  1:17 Install and configure the Cloudinary Node.js SDK to be able to use it from your server designated React component. Add your SDK code inside your asynchronous page component to perform a search. For example to find all images with "converse" in the name:

Search for images by tag

Jump to this spot in the video  2:10 Instead of returning all images or images by name, you can also search for images by tag. For example to find images with the tag "sneakers":

Use returned images on your page

Jump to this spot in the video  2:24 Use the returned Cloudinary images on your page by looping through the returned images. First, destructure the returned resources to get the resources array from the JSON. Use map to iterate through the resources array. If using typescript, reference the CloudinaryResource and define this as an interface with public_id and secure_url as strings. Update your list items to reference the public_id as the key and secure_url as the image src.

Take it further

Jump to this spot in the video  3:27 Take it further by learning all about how to add Cloudinary optimizations and transformations using Next Cloudinary.

Keep learning

Related topics

If you like this, you might also like...

Optimization Tips
Tips for delivering optimized images
Upload Assets with Server Actions
Upload assets to Cloudinary using Next.js Server Actions
Optimize Videos in Next.js
Optimize delivery of videos in a Next.js app

 

Cloudinary Academy

 

Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.

 

✔️ Feedback sent!

Rate this page: