| | |
| | | // 构建文件访问URL |
| | | String fileUrl = cosService.getFileUrl(relativePath); |
| | | |
| | | // 为兼容前端wangEditor,返回其期望的格式 |
| | | Map<String, Object> response = new HashMap<>(); |
| | | response.put("errno", 0); // 0表示成功,1表示失败 |
| | | response.put("success", true); |
| | | response.put("url", fileUrl); |
| | | response.put("fileName", originalFilename); // 保持原始文件名(带后缀) |
| | | response.put("fileSize", file.getSize()); |
| | | response.put("path", relativePath); // 只返回相对路径 |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("url", fileUrl); |
| | | data.put("alt", originalFilename); |
| | | data.put("href", fileUrl); |
| | | response.put("data", data); |
| | | |
| | | return ResponseEntity.ok(response); |
| | | } catch (Exception e) { |
| | | Map<String, Object> response = new HashMap<>(); |
| | | response.put("success", false); |
| | | response.put("error", e.getMessage()); |
| | | response.put("errno", 1); // 0表示成功,1表示失败 |
| | | response.put("message", e.getMessage()); |
| | | |
| | | return ResponseEntity.badRequest().body(response); |
| | | } |