| | |
| | | package com.se.simu.controller; |
| | | |
| | | import com.se.simu.domain.vo.R; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | @CrossOrigin(origins = "*") |
| | | @RestController |
| | | @RequestMapping("/v1/files") |
| | | public class FilesUploadController { |
| | | public class FilesUploadController extends BaseController { |
| | | |
| | | |
| | | @Value("${simu-app.filePath}") |
| | |
| | | |
| | | @ApiOperation("1-上传单个文件") |
| | | @PostMapping("/upload") |
| | | public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) throws IOException { |
| | | public R<Object> upload(@RequestParam("file") MultipartFile file) throws IOException { |
| | | if (file.isEmpty()) { |
| | | return success("文件不能为空"); |
| | | } |
| | | // 获取当前年月日 |
| | | String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | String targetDir = Paths.get(uploadedFolder, date).toString(); |
| | | log.info("目标目录: {}", targetDir); |
| | | createDirectoriesIfNotExists(targetDir); |
| | | try { |
| | | // 获取当前时分秒 |
| | | String time = LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")); |
| | | // 文件地址全称 |
| | | Path filePath = Paths.get(targetDir, time + "_" + file.getOriginalFilename()); |
| | | // 文件名 |
| | | file.transferTo(filePath); |
| | | return success(targetDir + "\\" + time + "_" + file.getOriginalFilename(), "文件上传成功"); |
| | | } catch (IOException e) { |
| | | log.error("文件上传失败", e); |
| | | return fail("文件上传失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ApiOperation("1-上传单个文件") |
| | | @PostMapping("/uploads") |
| | | public ResponseEntity<String> uploads(@RequestParam("file") MultipartFile file) throws IOException { |
| | | if (file.isEmpty()) { |
| | | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("文件不能为空"); |
| | | } |