12345678910111213141516171819202122232425262728293031323334353637 |
- package com.zhentao.information.controller;
- import com.zhentao.osspicture.OssUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import java.util.HashMap;
- import java.util.Map;
- @Slf4j
- @RestController
- public class FileController {
- @Autowired
- private OssUtil ossUtil;
- @PostMapping("/api/file/upload")
- public Map<String, Object> uploadFile(@RequestParam("file") MultipartFile file) {
- Map<String, Object> result = new HashMap<>();
- try {
- String fileUrl = ossUtil.uploadFile(file);
- result.put("url", fileUrl);
- result.put("fileName", file.getOriginalFilename());
- result.put("fileType", file.getContentType());
- result.put("fileSize", file.getSize());
- result.put("success", true);
- log.info("文件上传成功: {}", fileUrl);
- } catch (Exception e) {
- log.error("文件上传失败", e);
- result.put("success", false);
- result.put("message", "上传失败: " + e.getMessage());
- }
- return result;
- }
- }
|