package com.ruoyi.common.utils.file;

import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * JiangYuQi
 */
public class MultipartFileUtils {

    public static MultipartFile base64ToMultipartFile(String base64) throws IOException {
        String[] parts = base64.split(",");
        String contentType = parts[0].split(";")[0].split(":")[1];
        byte[] bytes = Base64.getDecoder().decode(parts[1]);
        return new MockMultipartFile("file", "file", contentType, bytes);
    }

}
