| | |
| | | } |
| | | } |
| | | |
| | | public static final String upload(String baseDir,String fileName,MultipartFile file) throws IOException { |
| | | try { |
| | | return upload(baseDir,fileName, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | } catch (Exception e) { |
| | | throw new IOException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |
| | | * |
| | |
| | | |
| | | String fileName = extractFilename(file); |
| | | |
| | | //String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); |
| | | String absPath = getAbsoluteFile(baseDir, fileName).getPath(); |
| | | file.transferTo(Paths.get(absPath)); |
| | | return getPathFileName(baseDir, fileName); |
| | | } |
| | | |
| | | public static final String upload(String baseDir,String fileName, MultipartFile file, String[] allowedExtension) |
| | | throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, |
| | | InvalidExtensionException { |
| | | int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length(); |
| | | if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) { |
| | | throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); |
| | | } |
| | | |
| | | assertAllowed(file, allowedExtension); |
| | | |
| | | fileName =StringUtils.format("{}/{}.{}", DateUtils.datePath(), |
| | | fileName, getExtension(file)); |
| | | |
| | | String absPath = getAbsoluteFile(baseDir, fileName).getPath(); |
| | | file.transferTo(Paths.get(absPath)); |
| | | return fileName; |
| | | } |
| | | |
| | | /** |
| | | * 编码文件名 |
| | | */ |
| | | public static final String extractFilename(MultipartFile file) { |
| | | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
| | | FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); |
| | | } |
| | | |
| | | public static final String extractXdtFilename(MultipartFile file) { |
| | | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
| | | FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); |
| | | } |
| | |
| | | public static final String getPathFileName(String uploadDir, String fileName) throws IOException { |
| | | int dirLastIndex = ltkjConfig.getProfile().length() + 1; |
| | | String currentDir = StringUtils.substring(uploadDir, dirLastIndex); |
| | | return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; |
| | | return Constants.RESOURCE_PREFIX + currentDir + "/" + fileName; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 文件大小校验 |
| | | * |