package com.seer.teach.common.utils;

import org.springframework.web.multipart.MultipartFile;

import java.util.Base64;

/**
 *
 * <p>
 *
 * </p >
 *
 * @author Captain
 * @since 2025-11-22 14:34
 */
public class FileUtils {

    public static MultipartFile base64ToMultipart(String base64) {
        try {
            String[] baseStrs = base64.split(",");
            byte[] bytes;

            if (baseStrs.length > 1) {
                bytes = Base64.getDecoder().decode(baseStrs[1]);
            } else {
                bytes = Base64.getDecoder().decode(base64);
            }

            return new Base64DecodedMultipartFile(bytes);
        }catch (Exception e){
            throw new RuntimeException("Base64转换Multipart失败");
        }
    }
}
