Media Uploader
A full-stack media upload component with drag-and-drop functionality, progress tracking, and cloud storage integration.
Media Uploader
A full-stack media upload component with drag-and-drop functionality, progress tracking, and cloud storage integration. Built with Next.js server actions and Cloudinary for seamless media management.
Installation
Install the component using the AxionsJS CLI:
Configure environment variables in your .env
file:
Make sure to keep your Cloudinary credentials secure and never expose them in client-side code.
Database Schema
The component uses Prisma with the following schema. Add this to your schema.prisma
file:
Run npx prisma db push
or npx prisma migrate dev
after adding the schema to apply changes to your database.
Usage
Import and use the MediaUploader component:
Server Actions
The component includes three main server actions for handling media operations:
Upload Media
Handles file upload to Cloudinary and database storage
Get Media
Retrieves all media from the database
Delete Media
Removes media from both Cloudinary and database
Upload Media
Get Media
Delete Media
Component Features
The MediaUploader component provides:
- Drag and Drop Interface: Intuitive file dropping area
- Multiple File Selection: Upload multiple files simultaneously
- Progress Tracking: Real-time upload progress indicators
- Error Handling: Comprehensive error handling with retry functionality
- File Validation: Client-side file type and size validation
API Reference
MediaUploader Props
Prop | Type | Default |
---|---|---|
className | string | - |
maxFiles | number | - |
maxFileSize | number | - |
onComplete | () => void | - |
MediaGallery Props
Prop | Type | Default |
---|---|---|
media | Media[] | - |
columns | number | - |
onDelete | (id: string) => void | - |
Media Object Type
Always implement proper error handling for production applications.
Best Practices
Server-side Validation Always validate files on the server:
Environment Security
- Never expose Cloudinary credentials in client code
- Use environment variables for all sensitive data
- Implement proper CORS policies
Conclusion
The Media Uploader component is a powerful and flexible solution for managing media uploads
in full-stack applications. It integrates seamlessly with Next.js
, Prisma
, and Cloudinary
, providing a robust set of features including drag-and-drop uploads, progress tracking, and error handling. The modular design allows for easy customization and extension, making it suitable for a wide range of applications from simple blogs to complex media management systems.