| | |
| | | } |
| | | |
| | | |
| | | /**文件转化 |
| | | * File to MultipartFile |
| | | * @param file 文件 |
| | | * @param fileName 带后缀的文件名 |
| | | * @return |
| | | */ |
| | | public static MultipartFile getMultipartFile(File file,String fileName) { |
| | | FileItem item = new DiskFileItemFactory().createItem("file" |
| | | , MediaType.MULTIPART_FORM_DATA_VALUE |
| | | , true |
| | | , StringUtils.isEmpty(fileName)?file.getName():fileName); |
| | | try (InputStream input = new FileInputStream(file); |
| | | OutputStream os = item.getOutputStream()) { |
| | | // 流转移 |
| | | IOUtils.copy(input, os); |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("Invalid file: " + e, e); |
| | | } |
| | | return new CommonsMultipartFile(item); |
| | | } |
| | | |
| | | } |