| | |
| | | |
| | | |
| | | @ApiOperation("1-上传单个文件") |
| | | @PostMapping("/upload") |
| | | public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) throws IOException { |
| | | if (file.isEmpty()) { |
| | | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("文件不能为空"); |
| | | } |
| | | String targetDir = Paths.get(uploadedFolder, "upload").toString(); |
| | | log.info("目标目录: {}", targetDir); |
| | | createDirectoriesIfNotExists(targetDir); |
| | | try { |
| | | file.transferTo(Paths.get(targetDir, file.getOriginalFilename())); |
| | | return ResponseEntity.ok("文件上传成功"); |
| | | } catch (IOException e) { |
| | | log.error("文件上传失败", e); |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件上传失败"); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("1-1 -上传单个文件") |
| | | @ApiImplicitParam(name = "filePathName", value = "文件夹名称", required = true, dataType = "String", paramType = "query", example = "upload", dataTypeClass = String.class) |
| | | @PostMapping("/uploadSingleFile") |
| | | public ResponseEntity<String> uploadSingleFile(@RequestParam("file") MultipartFile file, @RequestParam("filePathName") String filePathName) throws IOException { |