| | |
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.nio.file.Paths;
|
| | | import java.util.Objects;
|
| | | import org.apache.commons.io.FilenameUtils;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | |
| | | /**
|
| | | * 默认大小 50M
|
| | | */
|
| | | public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
|
| | | public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024L;
|
| | |
|
| | | /**
|
| | | * 默认的文件名最大长度 100
|
| | |
| | | throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
| | | InvalidExtensionException
|
| | | {
|
| | | int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
| | | if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
| | | int fileNameLength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
| | | if (fileNameLength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
| | | {
|
| | | throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
| | | }
|
| | |
| | |
|
| | | String fileName = extractFilename(file);
|
| | |
|
| | | File desc = getAbsoluteFile(baseDir, fileName);
|
| | | file.transferTo(desc);
|
| | | String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
| | | file.transferTo(Paths.get(absPath));
|
| | | return getPathFileName(baseDir, fileName);
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
|
| | | String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
| | | return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
| | | // return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
| | | return currentDir + "/" + fileName;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|