mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-18 00:38:33 +08:00
uploadFirmware 上传固件接口
This commit is contained in:
@@ -11,6 +11,7 @@ import com.jsowell.framework.config.ServerConfig;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -39,6 +40,9 @@ public class CommonController {
|
|||||||
|
|
||||||
private static final String FILE_DELIMETER = ",";
|
private static final String FILE_DELIMETER = ",";
|
||||||
|
|
||||||
|
@Value("${remoteUpdate.path}")
|
||||||
|
private String FIRMWARE_FILEPATH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用下载请求
|
* 通用下载请求
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -193,3 +193,4 @@ remoteUpdate:
|
|||||||
port: 21
|
port: 21
|
||||||
username: jsowellftp
|
username: jsowellftp
|
||||||
password: ZzJeZRB6fDRcnfkz
|
password: ZzJeZRB6fDRcnfkz
|
||||||
|
path: /www/wwwroot/jsowellftp
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# 项目相关配置
|
# 项目相关配置
|
||||||
jsowell:
|
jsowell:
|
||||||
# 文件路径 示例( Windows配置D:/jsowell/uploadPath,Linux配置 /home/jsowell/uploadPath)
|
# 文件路径 示例( Windows配置D:/jsowell/uploadPath,Linux配置 /home/jsowell/uploadPath)
|
||||||
profile: /var/ftp/firmware
|
profile: /www/wwwroot/jsowellftpprd
|
||||||
|
|
||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
@@ -189,3 +189,4 @@ remoteUpdate:
|
|||||||
port: 21
|
port: 21
|
||||||
username: jsowellftpprd
|
username: jsowellftpprd
|
||||||
password: ADHJAYinpXEctwDA
|
password: ADHJAYinpXEctwDA
|
||||||
|
path: /www/wwwroot/jsowellftpprd
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# 项目相关配置
|
# 项目相关配置
|
||||||
jsowell:
|
jsowell:
|
||||||
# 文件路径 示例( Windows配置D:/jsowell/uploadPath,Linux配置 /home/jsowell/uploadPath)
|
# 文件路径 示例( Windows配置D:/jsowell/uploadPath,Linux配置 /home/jsowell/uploadPath)
|
||||||
profile: /var/ftp/firmware
|
profile: /www/wwwroot/jsowellftpprd
|
||||||
|
|
||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
@@ -189,3 +189,4 @@ remoteUpdate:
|
|||||||
port: 21
|
port: 21
|
||||||
username: jsowellftpprd
|
username: jsowellftpprd
|
||||||
password: ADHJAYinpXEctwDA
|
password: ADHJAYinpXEctwDA
|
||||||
|
path: /www/wwwroot/jsowellftpprd
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
# 项目相关配置
|
# 项目相关配置
|
||||||
jsowell:
|
jsowell:
|
||||||
# 文件路径 示例( Windows配置D:/jsowell/uploadPath,Linux配置 /home/jsowell/uploadPath)
|
# 文件路径 示例( Windows配置D:/jsowell/uploadPath,Linux配置 /home/jsowell/uploadPath)
|
||||||
profile: /var/ftp/firmware
|
profile: /www/wwwroot/jsowellftp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
@@ -194,3 +192,4 @@ remoteUpdate:
|
|||||||
port: 21
|
port: 21
|
||||||
username: jsowellftp
|
username: jsowellftp
|
||||||
password: ZzJeZRB6fDRcnfkz
|
password: ZzJeZRB6fDRcnfkz
|
||||||
|
path: /www/wwwroot/jsowellftp
|
||||||
@@ -98,15 +98,20 @@ public class FileUploadUtils {
|
|||||||
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
|
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
|
||||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
||||||
InvalidExtensionException {
|
InvalidExtensionException {
|
||||||
|
// 文件名长度
|
||||||
int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
||||||
|
// 文件名长度 不能大于100
|
||||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
|
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
|
||||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 文件大小校验
|
||||||
assertAllowed(file, allowedExtension);
|
assertAllowed(file, allowedExtension);
|
||||||
|
|
||||||
|
// 编码文件名
|
||||||
String fileName = extractFilename(file);
|
String fileName = extractFilename(file);
|
||||||
|
|
||||||
|
// 获取绝对文件路径
|
||||||
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
||||||
file.transferTo(Paths.get(absPath));
|
file.transferTo(Paths.get(absPath));
|
||||||
return getPathFileName(baseDir, fileName);
|
return getPathFileName(baseDir, fileName);
|
||||||
@@ -163,11 +168,16 @@ public class FileUploadUtils {
|
|||||||
* 编码文件名
|
* 编码文件名
|
||||||
*/
|
*/
|
||||||
public static final String extractFilename(MultipartFile file) {
|
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));
|
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 {
|
public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {
|
||||||
File desc = new File(uploadDir + File.separator + fileName);
|
File desc = new File(uploadDir + File.separator + fileName);
|
||||||
|
|
||||||
@@ -179,10 +189,10 @@ public class FileUploadUtils {
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取文件路径名称
|
||||||
public static final String getPathFileName(String uploadDir, String fileName) throws IOException {
|
public static final String getPathFileName(String uploadDir, String fileName) throws IOException {
|
||||||
int dirLastIndex = JsowellConfig.getProfile().length() + 1;
|
int dirLastIndex = JsowellConfig.getProfile().length() + 1;
|
||||||
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
||||||
// return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
|
||||||
return currentDir + "/" + fileName;
|
return currentDir + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
# 页面标题
|
# 页面标题
|
||||||
VUE_APP_TITLE = 万车充后台管理系统
|
VUE_APP_TITLE = 万车充后台管理系统
|
||||||
|
|
||||||
NODE_ENV = production
|
|
||||||
|
|
||||||
# 测试环境配置
|
# 测试环境配置
|
||||||
ENV = 'staging'
|
ENV = 'staging'
|
||||||
|
|
||||||
# 万车充后台管理系统/测试环境
|
# 万车充后台管理系统/测试环境
|
||||||
VUE_APP_BASE_API = '/dev-api'
|
VUE_APP_BASE_API = '/dev-api'
|
||||||
|
|
||||||
|
# 开发环境配置
|
||||||
|
NODE_ENV = production
|
||||||
|
|
||||||
|
# 路由懒加载
|
||||||
|
VUE_CLI_BABEL_TRANSPILE_MODULES = true
|
||||||
|
|||||||
Reference in New Issue
Block a user