mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
uploadFirmware 上传固件接口
This commit is contained in:
@@ -98,15 +98,20 @@ public class FileUploadUtils {
|
||||
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
|
||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
||||
InvalidExtensionException {
|
||||
// 文件名长度
|
||||
int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
||||
// 文件名长度 不能大于100
|
||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
|
||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||
}
|
||||
|
||||
// 文件大小校验
|
||||
assertAllowed(file, allowedExtension);
|
||||
|
||||
// 编码文件名
|
||||
String fileName = extractFilename(file);
|
||||
|
||||
// 获取绝对文件路径
|
||||
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
||||
file.transferTo(Paths.get(absPath));
|
||||
return getPathFileName(baseDir, fileName);
|
||||
@@ -163,11 +168,16 @@ public class FileUploadUtils {
|
||||
* 编码文件名
|
||||
*/
|
||||
public static final String extractFilename(MultipartFile file) {
|
||||
// return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
|
||||
// return StringUtils.format("{}/{}.{}", DateUtils.datePath(), FilenameUtils.getBaseName(file.getOriginalFilename()), getExtension(file));
|
||||
return StringUtils.format("{}.{}", FilenameUtils.getBaseName(file.getOriginalFilename()), getExtension(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取绝对文件
|
||||
* @param uploadDir
|
||||
* @param fileName
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {
|
||||
File desc = new File(uploadDir + File.separator + fileName);
|
||||
|
||||
@@ -179,10 +189,10 @@ public class FileUploadUtils {
|
||||
return desc;
|
||||
}
|
||||
|
||||
// 获取文件路径名称
|
||||
public static final String getPathFileName(String uploadDir, String fileName) throws IOException {
|
||||
int dirLastIndex = JsowellConfig.getProfile().length() + 1;
|
||||
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
||||
// return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
||||
return currentDir + "/" + fileName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user