| | |
| | | @RequestMapping(value = "/fileUpload") |
| | | public class FileUploadController extends BaseController { |
| | | |
| | | // @Value("${file.upload.dir}") |
| | | private String uploadDir = "d:/upload/files"; |
| | | // 基础上传目录 |
| | | private String baseUploadDir = "/home/javaweb/webresource/ai"; |
| | | |
| | | // @Value("${file.chunk.dir}") |
| | | private String chunkDir = "d:/upload/chunks"; |
| | | // 分片存储目录 |
| | | private String baseChunkDir = "/home/javaweb/webresource/ai/chunks"; |
| | | |
| | | /** |
| | | * 上传文件分片 |
| | |
| | | @RequestParam("chunks") int chunks, |
| | | @RequestParam("fileMd5") String fileMd5) { |
| | | try { |
| | | String companyId = getCurrentUserCompanyId(); |
| | | // 构建公司专属分片目录 |
| | | String chunkDir = baseChunkDir + "/" + companyId; |
| | | // 确保分片目录存在 |
| | | Path chunkPath = Paths.get(chunkDir, fileMd5); |
| | | if (!Files.exists(chunkPath)) { |
| | |
| | | @RequestParam("fileMd5") String fileMd5, |
| | | @RequestParam("chunks") int chunks) { |
| | | try { |
| | | |
| | | String companyId = getCurrentUserCompanyId(); |
| | | // 构建公司专属上传目录 |
| | | String uploadDir = baseUploadDir + "/" + companyId; |
| | | // 确保上传目录存在 |
| | | Path uploadPath = Paths.get(uploadDir); |
| | | if (!Files.exists(uploadPath)) { |
| | |
| | | String uniqueFileName = UUID.randomUUID().toString() + "_" + fileName; |
| | | Path targetFilePath = uploadPath.resolve(uniqueFileName); |
| | | |
| | | // 构建公司专属分片目录 |
| | | String chunkDir = baseChunkDir + "/" + companyId; |
| | | // 确保分片目录存在 |
| | | Path chunkPath = Paths.get(chunkDir, fileMd5); |
| | | if (!Files.exists(chunkPath)) { |
| | |
| | | @GetMapping("/play/{fileName}") |
| | | public void playVideo(@PathVariable("fileName") String fileName, HttpServletResponse response) { |
| | | try { |
| | | String companyId = getCurrentUserCompanyId(); |
| | | String uploadDir = baseUploadDir + "/" + companyId; |
| | | Path filePath = Paths.get(uploadDir, fileName); |
| | | if (!Files.exists(filePath)) { |
| | | response.setStatus(HttpStatus.NOT_FOUND.value()); |
| | |
| | | @GetMapping("/list") |
| | | public FebsResponse getFileList() { |
| | | try { |
| | | |
| | | String companyId = getCurrentUserCompanyId(); |
| | | String uploadDir = baseUploadDir + "/" + companyId; |
| | | Path uploadPath = Paths.get(uploadDir); |
| | | if (!Files.exists(uploadPath)) { |
| | | return new FebsResponse().data(new ArrayList<>()); |
| | |
| | | @PostMapping("/delete") |
| | | public FebsResponse deleteFile(@RequestParam("fileName") String fileName) { |
| | | try { |
| | | |
| | | String companyId = getCurrentUserCompanyId(); |
| | | String uploadDir = baseUploadDir + "/" + companyId; |
| | | Path filePath = Paths.get(uploadDir, fileName); |
| | | if (Files.exists(filePath)) { |
| | | Files.delete(filePath); |