canvas-backend/src/helper/upload/uploadToMinio.ts
2025-02-01 17:43:17 +06:00

18 lines
No EOL
751 B
TypeScript

import { minioClient } from "../../config/minioClient";
export const uploadToMinio = async (file: File, bucketName: string, objectName: string) => {
const buffer = Buffer.from(await file.arrayBuffer()); // Convert file to buffer
try {
// Ensure the file is uploaded to MinIO
await minioClient.putObject(bucketName, objectName, buffer);
// Construct the public URL to access the uploaded file
const publicUrl = `${minioClient.protocol}//${minioClient.host}:${minioClient.port}/${bucketName}/${objectName}`;
return { url: publicUrl };
} catch (error: any) {
console.error("Error uploading file to MinIO:", error);
throw new Error(`Error uploading file: ${error.message}`);
}
};