@@ -14,16 +14,19 @@ const APPDEV_BUCKET = "alumni-website";
1414async function uploadToAppDev ( buffer : Buffer , filename : string ) : Promise < string > {
1515 const form = new FormData ( ) ;
1616 form . append ( "bucket" , APPDEV_BUCKET ) ;
17- form . append ( "image" , new File ( [ new Uint8Array ( buffer ) ] , filename , { type : "image/webp" } ) ) ;
18- console . log ( "[avatar/appdev] uploading to" , UPLOAD_URL , { bucket : APPDEV_BUCKET , filename, bytes : buffer . byteLength } ) ;
17+ // Use .jpg extension — older Python mimetypes doesn't recognize .webp
18+ const uploadFilename = filename . replace ( / \. \w + $ / , ".jpg" ) ;
19+ form . append ( "image" , new File ( [ new Uint8Array ( buffer ) ] , uploadFilename , { type : "image/jpeg" } ) ) ;
20+ console . log ( "[avatar/appdev] uploading to" , UPLOAD_URL , { bucket : APPDEV_BUCKET , filename : uploadFilename , bytes : buffer . byteLength } ) ;
1921 const res = await fetch ( UPLOAD_URL , { method : "POST" , body : form } ) ;
2022 console . log ( "[avatar/appdev] response status" , res . status ) ;
2123 if ( ! res . ok ) {
2224 const body = await res . text ( ) ;
2325 console . error ( "[avatar/appdev] upload failed" , { status : res . status , body } ) ;
2426 throw new Error ( `AppDev upload failed: ${ res . status } ${ body } ` ) ;
2527 }
26- const url = ( await res . text ( ) ) . trim ( ) ;
28+ const json = await res . json ( ) ;
29+ const url = json . data as string ;
2730 console . log ( "[avatar/appdev] uploaded url" , url ) ;
2831 return url ;
2932}
@@ -37,13 +40,13 @@ async function removeFromAppDev(imageUrl: string): Promise<void> {
3740}
3841
3942async function uploadToEmulator ( buffer : Buffer , uid : string ) : Promise < string > {
40- const filePath = `profile-pictures/${ uid } .webp ` ;
43+ const filePath = `profile-pictures/${ uid } .jpg ` ;
4144 const bucket = adminStorage . bucket ( BUCKET ) ;
4245 const fileRef = bucket . file ( filePath ) ;
4346 const token = crypto . randomUUID ( ) ;
4447 await fileRef . save ( buffer , {
4548 metadata : {
46- contentType : "image/webp " ,
49+ contentType : "image/jpeg " ,
4750 metadata : { firebaseStorageDownloadTokens : token } ,
4851 } ,
4952 } ) ;
@@ -52,7 +55,7 @@ async function uploadToEmulator(buffer: Buffer, uid: string): Promise<string> {
5255
5356async function removeFromEmulator ( uid : string ) : Promise < void > {
5457 try {
55- const filePath = `profile-pictures/${ uid } .webp ` ;
58+ const filePath = `profile-pictures/${ uid } .jpg ` ;
5659 await adminStorage . bucket ( BUCKET ) . file ( filePath ) . delete ( ) ;
5760 } catch {
5861 // file may not exist yet
@@ -75,7 +78,7 @@ export async function POST(request: NextRequest) {
7578 const arrayBuffer = await file . arrayBuffer ( ) ;
7679 const processed = await sharp ( Buffer . from ( arrayBuffer ) )
7780 . resize ( SIZE , SIZE , { fit : "cover" } )
78- . webp ( { quality : 85 } )
81+ . jpeg ( { quality : 85 } )
7982 . toBuffer ( ) ;
8083
8184 console . log ( "[avatar] processed buffer size" , processed . byteLength ) ;
@@ -94,7 +97,7 @@ export async function POST(request: NextRequest) {
9497 const url =
9598 process . env . NODE_ENV === "development"
9699 ? await uploadToEmulator ( processed , uid )
97- : await uploadToAppDev ( processed , `${ uid } .webp ` ) ;
100+ : await uploadToAppDev ( processed , `${ uid } .jpg ` ) ;
98101
99102 await updateUserProfile ( uid , { profilePictureUrl : url } ) ;
100103
0 commit comments