diff --git a/src/app/actions/upload.ts b/src/app/actions/upload.ts index 13dace8..f02925b 100644 --- a/src/app/actions/upload.ts +++ b/src/app/actions/upload.ts @@ -2,13 +2,14 @@ import { PutObjectCommand } from "@aws-sdk/client-s3"; import { s3Client, BUCKET_NAME } from "@/lib/s3"; +import { initMinio } from "@/lib/init-minio"; import { v4 as uuidv4 } from "uuid"; -// Get the public URL for MinIO files +// Get the public URL for files // In production, files are served through /api/files proxy function getPublicUrl(fileName: string): string { // Always use our API proxy route to serve files - // This ensures files are accessible even when MinIO is not publicly exposed + // This ensures files are accessible even when storage is not publicly exposed return `/api/files/${BUCKET_NAME}/${fileName}`; } @@ -19,6 +20,9 @@ export async function uploadFile(formData: FormData) { throw new Error("No file provided"); } + // Ensure bucket exists before upload + await initMinio(); + const buffer = Buffer.from(await file.arrayBuffer()); const fileName = `${uuidv4()}-${file.name}`; @@ -34,9 +38,8 @@ export async function uploadFile(formData: FormData) { // Return the URL to access the file const url = getPublicUrl(fileName); return { success: true, url, fileName }; - } catch (error) { + } catch (error: any) { console.error("Upload error:", error); - return { success: false, error: "Failed to upload file" }; + return { success: false, error: error.message || "Failed to upload file" }; } } - diff --git a/src/app/setup/page.tsx b/src/app/setup/page.tsx index 8d40a06..2c61386 100644 --- a/src/app/setup/page.tsx +++ b/src/app/setup/page.tsx @@ -206,7 +206,7 @@ export default function SetupPage() { {isUploading ? (
-

Enviando para o MinIO...

+

Enviando...

) : formData.logoUrl ? (
@@ -217,7 +217,7 @@ export default function SetupPage() { <>

Arraste sua logo ou clique para buscar

-

PNG, JPG até 5MB (Será salva no MinIO)

+

PNG, JPG até 5MB

)}