package com.vetti.common.utils;

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

import java.io.File;
import java.io.FileInputStream;

public class MultipartFileUtil {

    public static MultipartFile fileToMultipartFile(File file) throws Exception {
        try (FileInputStream inputStream = new FileInputStream(file)) {
            return new MockMultipartFile(
                    "file",                 // 表单字段名
                    file.getName(),          // 原始文件名
                    "application/octet-stream", // Content-Type
                    inputStream
            );
        }
    }
}

