|
@@ -63,7 +63,7 @@
|
|
|
// @ApiOperation(value = "后台上传文件")
|
|
|
// @RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
|
// @CrossOrigin
|
|
|
-// public ResponseObject uploadFileLocal(HttpServletRequest request) {
|
|
|
+// public ResponseObject fileLocal(HttpServletRequest request) {
|
|
|
// String token = request.getHeader("Access-Token");
|
|
|
// String action = request.getParameter("action") == null ? "" : request.getParameter("action");
|
|
|
//
|
|
@@ -206,10 +206,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -248,27 +245,27 @@ public class BackendFileController extends BaseController {
|
|
|
/**
|
|
|
* 后台上传文件
|
|
|
*
|
|
|
- * @param uploadFile
|
|
|
+ * @param file
|
|
|
* @param token
|
|
|
* @return ResponseObject
|
|
|
*/
|
|
|
@ApiOperation(value = "后台上传文件")
|
|
|
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
|
@CrossOrigin
|
|
|
- public ResponseObject uploadFileLocal(MultipartFile uploadFile, String token) {
|
|
|
-// // 验证 token 是否有效
|
|
|
+ public ResponseObject fileLocal(@RequestParam("file") MultipartFile file) {
|
|
|
+ // 验证 token 是否有效
|
|
|
// AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
// if (accountInfo == null) {
|
|
|
// return getFailureResult(1001, "请先登录");
|
|
|
// }
|
|
|
|
|
|
// 校验上传的文件是否为空
|
|
|
- if (uploadFile == null || uploadFile.isEmpty()) {
|
|
|
+ if (file == null || file.isEmpty()) {
|
|
|
return getFailureResult(201, "上传的文件不能为空");
|
|
|
}
|
|
|
|
|
|
// 获取文件的原始文件名
|
|
|
- String originalFilename = uploadFile.getOriginalFilename();
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
if (StringUtil.isEmpty(originalFilename)) {
|
|
|
return getFailureResult(201, "上传文件获取失败");
|
|
|
}
|
|
@@ -283,16 +280,16 @@ public class BackendFileController extends BaseController {
|
|
|
}
|
|
|
|
|
|
// 判断文件大小
|
|
|
- if (uploadFile.getSize() > (maxSize * 1024 * 1024)) {
|
|
|
+ if (file.getSize() > (maxSize * 1024 * 1024)) {
|
|
|
return getFailureResult(201, "上传的文件不能大于 " + maxSize + "MB");
|
|
|
}
|
|
|
|
|
|
// 获取文件类型
|
|
|
- String fileType = uploadFile.getContentType();
|
|
|
+ String fileType = file.getContentType();
|
|
|
|
|
|
// 保存文件并上传到华为云OBS
|
|
|
try {
|
|
|
- String fileName = saveFile(uploadFile);
|
|
|
+ String fileName = saveFile(file);
|
|
|
String baseImage = settingService.getUploadBasePath();
|
|
|
String filePath = baseImage + fileName;
|
|
|
String url = filePath;
|
|
@@ -328,10 +325,10 @@ public class BackendFileController extends BaseController {
|
|
|
resultMap.put("filePath", filePath);
|
|
|
resultMap.put("fileName", fileName);
|
|
|
resultMap.put("state", "SUCCESS");
|
|
|
- resultMap.put("original", uploadFile.getOriginalFilename());
|
|
|
- resultMap.put("size", uploadFile.getSize() + "");
|
|
|
+ resultMap.put("original", file.getOriginalFilename());
|
|
|
+ resultMap.put("size", file.getSize() + "");
|
|
|
resultMap.put("title", fileName);
|
|
|
- resultMap.put("type", uploadFile.getContentType());
|
|
|
+ resultMap.put("type", file.getContentType());
|
|
|
resultMap.put("url", url);
|
|
|
String ip = CommonUtil.getIPFromHttpRequest(null);
|
|
|
logger.info("用户ip:{},上传文件url:{}", ip, url);
|
|
@@ -345,12 +342,12 @@ public class BackendFileController extends BaseController {
|
|
|
/**
|
|
|
* 保存文件到本地磁盘
|
|
|
*
|
|
|
- * @param uploadFile
|
|
|
+ * @param file
|
|
|
* @return 文件路径
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public String saveFile(MultipartFile uploadFile) throws Exception {
|
|
|
- String fileName = uploadFile.getOriginalFilename();
|
|
|
+ public String saveFile(MultipartFile file) throws Exception {
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
String fileExtension = fileName.substring(fileName.lastIndexOf("."));
|
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
|
@@ -367,7 +364,7 @@ public class BackendFileController extends BaseController {
|
|
|
if (!tempFile.getParentFile().exists()) {
|
|
|
tempFile.getParentFile().mkdirs();
|
|
|
}
|
|
|
- CommonUtil.saveMultipartFile(uploadFile, pathRoot + path);
|
|
|
+ CommonUtil.saveMultipartFile(file, pathRoot + path);
|
|
|
} catch (Exception e) {
|
|
|
throw new Exception("上传失败,请检查目录是否可写");
|
|
|
}
|