1- /**
2- * Cloudinary fast upload utility supporting images & videos with progress
3- * Combines secure server-side config + client-side parallel uploads
4- */
5-
61import { v2 as cloudinary } from 'cloudinary' ;
72import type { UploadApiResponse } from 'cloudinary' ;
83
@@ -22,7 +17,7 @@ export const uploadMediaServer = async (
2217 try {
2318 const result = await cloudinary . uploader . upload ( filePath , {
2419 folder,
25- resource_type : 'auto' , // auto-detect image/video
20+ resource_type : 'auto' ,
2621 transformation : [ { quality : 'auto' , fetch_format : 'auto' } ] ,
2722 } ) ;
2823 console . log ( `[Cloudinary] ✅ Uploaded (server): ${ result . secure_url } ` ) ;
@@ -33,10 +28,11 @@ export const uploadMediaServer = async (
3328 }
3429} ;
3530
36- // ==== CLIENT-SIDE UPLOAD ====
31+ // ==== CLIENT-SIDE UPLOAD LIMITS ====
3732const MAX_BROWSER_IMAGE_SIZE = 1.5 * 1024 * 1024 ; // 1.5 MB
38- const MAX_BROWSER_VIDEO_SIZE = 5 * 1024 * 1024 ; // 5 MB
33+ const MAX_BROWSER_VIDEO_SIZE = 10 * 1024 * 1024 ; // 10 MB
3934
35+ // ==== CLIENT-SIDE UPLOAD ====
4036export const uploadMedia = async (
4137 file : File | Blob ,
4238 onProgress ?: ( progress : number ) => void ,
@@ -45,13 +41,10 @@ export const uploadMedia = async (
4541 const isVideo = ( file as File ) . type . startsWith ( 'video' ) ;
4642 const uploadType = isVideo ? 'video' : 'image' ;
4743
48- // Fallback to server-side if file is too large
44+ // Browser size validation
4945 if ( ( isVideo && file . size > MAX_BROWSER_VIDEO_SIZE ) || ( ! isVideo && file . size > MAX_BROWSER_IMAGE_SIZE ) ) {
50- // You need a helper to save the blob to a temporary file path on server/Termux
51- // Example: const tempFilePath = await saveBlobToTempFile(file);
52- // return (await uploadMediaServer(tempFilePath)).secure_url;
5346 console . warn ( `[Cloudinary] File too large for browser upload, fallback to server-side required` ) ;
54- throw new Error ( 'File too large for browser upload, use server-side upload instead .' ) ;
47+ throw new Error ( 'File too large for browser upload. Use server-side upload.' ) ;
5548 }
5649
5750 const formData = new FormData ( ) ;
0 commit comments