Image & Video APIs

Upload images in Astro (video tutorial)

Last updated: Mar-10-2026

Overview

Learn how to upload images to Cloudinary from an HTML form in an Astro application. This tutorial demonstrates how to configure Astro for server-side rendering, handle multipart form data, and use the Cloudinary Node.js SDK upload_stream method to upload files directly from memory without saving them to disk.

Video tutorial


This video is brought to you by Cloudinary's video player - embed your own!
Use the controls to set the playback speed, navigate to chapters of interest and select subtitles in your preferred language.

Tutorial contents

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

Introduction to Astro

Jump to this spot in the video  0:00 Astro ships zero client-side JavaScript by default. To handle user-generated content like file uploads, use Astro's server-side capabilities with a regular HTML form. Change the output config value from its default static to server or hybrid to enable server-side rendering.

Creating the upload form

Jump to this spot in the video  0:44 Create an upload form with a file picker, a label, and a submit button. The form should send a POST request and use multipart/form-data encoding so the file data is included in the request. Code in the frontmatter of an Astro file executes on the server and is never shipped to the client.

Handling form submission

Jump to this spot in the video  1:36 When the POST request comes in, cast the incoming file to an actual file object before processing it for upload.

Uploading to Cloudinary

Jump to this spot in the video  1:41 Use the Cloudinary Node.js SDK upload_stream method to upload the file. Create a helper function that takes a file as binary data along with a Cloudinary options object and returns a promise. Convert the file to binary data in two steps: first to a buffer array, then to a Uint8Array of 8-bit unsigned integers. The binary data is sent as a single chunk using end.

Displaying uploaded files

Jump to this spot in the video  2:42 Capture the Cloudinary upload response and conditionally render either the form or a preview of the uploaded image. Use the unpic library to apply on-the-fly transformations such as resizing and format conversion for an optimized preview.

AI in media management

Jump to this spot in the video  3:24 Media libraries can grow unwieldy without proper organization. Cloudinary offers AI-powered content analysis to automatically categorize and tag images, reducing manual asset management effort.

Keep learning

Related topics

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

 

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:

one star two stars three stars four stars five stars