@@ -50,7 +50,9 @@ export async function POST(req: Request) {
50
50
if ( ! process . env . NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET ) {
51
51
return NextResponse . json ( { message : "ServerMisconfig" } , { status : 500 } ) ;
52
52
}
53
- const count : number = await Paper . countDocuments ( ) ;
53
+ await connectToDatabase ( ) ;
54
+
55
+ const count : number = await PaperAdmin . countDocuments ( ) ;
54
56
const configIndex = count % cloudinaryConfigs . length ;
55
57
const selectedConfig = cloudinaryConfigs [ configIndex ] ;
56
58
cloudinary . v2 . config ( selectedConfig ) ;
@@ -66,7 +68,7 @@ export async function POST(req: Request) {
66
68
const bytes = await files [ 0 ] ?. arrayBuffer ( ) ;
67
69
if ( bytes ) {
68
70
const buffer = Buffer . from ( bytes ) ;
69
- imageURL = `data: ${ "image/png" } ;base64, ${ buffer . toString ( "base64" ) } ` ;
71
+ imageURL = buffer . toString ( "base64" ) ; // Plain Base64 string, no data URL prefix
70
72
}
71
73
}
72
74
const tags = await processAndAnalyze ( { imageURL } ) ;
@@ -125,7 +127,6 @@ export async function POST(req: Request) {
125
127
126
128
// If all checks pass, continue with the rest of the logic
127
129
128
- await connectToDatabase ( ) ;
129
130
let finalUrl : string | undefined = "" ;
130
131
let public_id_cloudinary : string | undefined = "" ;
131
132
let thumbnailUrl : string | undefined = "" ;
0 commit comments