| | |
| | | * @return 文件名称 |
| | | * @throws Exception |
| | | */ |
| | | public static final String upload(MultipartFile file) throws IOException |
| | | public static final String upload(MultipartFile file,String fname) throws IOException |
| | | { |
| | | try |
| | | { |
| | | return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION,fname); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | * @return 文件名称 |
| | | * @throws IOException |
| | | */ |
| | | public static final String upload(String baseDir, MultipartFile file) throws IOException |
| | | public static final String upload(String baseDir, MultipartFile file,String fname) throws IOException |
| | | { |
| | | try |
| | | { |
| | | return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION,fname); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | * @throws IOException 比如读写文件出错时 |
| | | * @throws InvalidExtensionException 文件校验异常 |
| | | */ |
| | | public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) |
| | | public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension,String fname) |
| | | throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, |
| | | InvalidExtensionException |
| | | { |
| | |
| | | |
| | | assertAllowed(file, allowedExtension); |
| | | |
| | | String fileName = extractFilename(file); |
| | | String fileName = extractFilename(file,fname); |
| | | |
| | | String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); |
| | | file.transferTo(Paths.get(absPath)); |
| | |
| | | /** |
| | | * 编码文件名 |
| | | */ |
| | | public static final String extractFilename(MultipartFile file) |
| | | public static final String extractFilename(MultipartFile file,String fname) |
| | | { |
| | | if (StringUtils.isNotEmpty(fname)){ |
| | | return fname+'.'+getExtension(file); |
| | | } |
| | | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
| | | FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); |
| | | } |