feat: implement business detail client view with interactive features including rating, favoriting, messaging, and analytics tracking
This commit is contained in:
28
app/actions/upload.ts
Normal file
28
app/actions/upload.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
'use server';
|
||||
|
||||
export async function uploadImage(formData: FormData) {
|
||||
try {
|
||||
const file = formData.get('file') as File;
|
||||
if (!file) {
|
||||
return { success: false, error: 'Aucun fichier fourni' };
|
||||
}
|
||||
|
||||
// Convert file to buffer
|
||||
const bytes = await file.arrayBuffer();
|
||||
const buffer = Buffer.from(bytes);
|
||||
|
||||
// Convert to Base64
|
||||
const base64 = buffer.toString('base64');
|
||||
const mimeType = file.type || 'image/jpeg';
|
||||
const dataUrl = `data:${mimeType};base64,${base64}`;
|
||||
|
||||
// Return the data URL directly (it will be saved in the database)
|
||||
return {
|
||||
success: true,
|
||||
url: dataUrl
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error during image conversion:', error);
|
||||
return { success: false, error: 'Erreur lors de la conversion de l\'image' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user