package com.example.backend.core.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Base64;

public final class ToBase64 {
    private ToBase64() {
    }

    public static String getBase64FromFile(MultipartFile file) {
        if (file != null && !file.isEmpty()) {
            try {
                String mimeType = file.getContentType();
                byte[] bytes = file.getBytes();
                return "data:" + mimeType + ";base64," + Base64.getEncoder().encodeToString(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "";
    }
}
