uploadFirmware 上传固件接口

This commit is contained in:
Guoqs
2024-05-21 15:18:39 +08:00
parent 5832610f74
commit 724d3ca4b7
7 changed files with 34 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ import com.jsowell.framework.config.ServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@@ -39,6 +40,9 @@ public class CommonController {
private static final String FILE_DELIMETER = ",";
@Value("${remoteUpdate.path}")
private String FIRMWARE_FILEPATH;
/**
* 通用下载请求
*

View File

@@ -192,4 +192,5 @@ remoteUpdate:
server: http://apitest.jsowellcloud.com
port: 21
username: jsowellftp
password: ZzJeZRB6fDRcnfkz
password: ZzJeZRB6fDRcnfkz
path: /www/wwwroot/jsowellftp

View File

@@ -1,7 +1,7 @@
# 项目相关配置
jsowell:
# 文件路径 示例( Windows配置D:/jsowell/uploadPathLinux配置 /home/jsowell/uploadPath
profile: /var/ftp/firmware
profile: /www/wwwroot/jsowellftpprd
# 数据源配置
spring:
@@ -188,4 +188,5 @@ remoteUpdate:
server: http://apitest.jsowellcloud.com
port: 21
username: jsowellftpprd
password: ADHJAYinpXEctwDA
password: ADHJAYinpXEctwDA
path: /www/wwwroot/jsowellftpprd

View File

@@ -1,7 +1,7 @@
# 项目相关配置
jsowell:
# 文件路径 示例( Windows配置D:/jsowell/uploadPathLinux配置 /home/jsowell/uploadPath
profile: /var/ftp/firmware
profile: /www/wwwroot/jsowellftpprd
# 数据源配置
spring:
@@ -188,4 +188,5 @@ remoteUpdate:
server: http://apitest.jsowellcloud.com
port: 21
username: jsowellftpprd
password: ADHJAYinpXEctwDA
password: ADHJAYinpXEctwDA
path: /www/wwwroot/jsowellftpprd

View File

@@ -1,9 +1,7 @@
# 项目相关配置
jsowell:
# 文件路径 示例( Windows配置D:/jsowell/uploadPathLinux配置 /home/jsowell/uploadPath
profile: /var/ftp/firmware
profile: /www/wwwroot/jsowellftp
# 数据源配置
spring:
@@ -193,4 +191,5 @@ remoteUpdate:
server: http://apitest.jsowellcloud.com
port: 21
username: jsowellftp
password: ZzJeZRB6fDRcnfkz
password: ZzJeZRB6fDRcnfkz
path: /www/wwwroot/jsowellftp

View File

@@ -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;
}

View File

@@ -1,10 +1,14 @@
# 页面标题
VUE_APP_TITLE = 万车充后台管理系统
NODE_ENV = production
# 测试环境配置
ENV = 'staging'
# 万车充后台管理系统/测试环境
VUE_APP_BASE_API = '/dev-api'
# 开发环境配置
NODE_ENV = production
# 路由懒加载
VUE_CLI_BABEL_TRANSPILE_MODULES = true