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
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
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
| When the POST request comes in, cast the incoming file to an actual file object before processing it for upload. |
Uploading to Cloudinary
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
| 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
| 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
- Watch more Dev Hints videos on the Cloudinary YouTube channel.
- Learn more about uploading images and the available upload options.
- Explore the Node.js SDK for server-side integration with Cloudinary.
- See how to upload images and videos using the Node.js SDK including the
upload_streammethod. - Discover the Astro Cloudinary components for client-side integration.
If you like this, you might also like...
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.
