peng
2025-11-06 c4938f6f4e839890b032c75c7a57333a6a9157a9
backend/src/main/java/com/rongyichuang/common/api/FileUploadController.java
@@ -35,18 +35,22 @@
            // 构建文件访问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);
        }