Features
Upload media
Use Whop to upload images, videos, audio, and other files.
Client-Side: Set up the Image Upload Component
First, create a component to handle image uploads. This example uses react-dropzone
for the file upload interface.
Server-Side: Handle File Uploads
Create an API route to handle the file upload using the Whop SDK:
Using Uploaded Media
After uploading, you can use the attachment ID in various Whop features. For example, to create a forum post with the uploaded image (server-side):
Supported File Types
The Whop API supports the following file types for upload:
- Images:
.jpg
,.jpeg
,.png
,.gif
- Videos:
.mp4
,.mov
- Documents:
.pdf
Best Practices
- File Size: Keep uploads under 100MB for optimal performance
- Image Optimization: Consider using libraries like
sharp
for image processing before upload - Error Handling: Implement proper error handling on both client and server
- Clean Up: Remember to clean up any preview URLs to prevent memory leaks
- Security: Always verify user authentication before handling uploads
- Progress Tracking: Consider implementing upload progress tracking for better UX
Complete Example
Here’s a complete example showing both client and server integration:
This implementation provides a complete media upload solution with:
- Drag and drop interface
- File preview
- Upload handling
- Progress states
- Error handling
- Automatic cleanup