5.3.6 API接口import com.itheima.fdfs.demo.common.FileDfsUtil;import io.swagger.annotations.ApiOperation;import org.springframework.http.ResponseEntity;import org.springframework.util.StringUtils;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.multipart.MultipartFile;import javax.annotation.Resource;@RestControllerpublic class FileController {@Resourceprivate FileDfsUtil fileDfsUtil ;/*** http://localhost:8081/swagger-ui.html*/@ApiOperation(value="https://www.huyubaike.com/biancheng/上传文件", notes="测试FastDFS文件上传")@RequestMapping(value = "https://www.huyubaike.com/uploadFile",headers="content-type=multipart/form-data", method = RequestMethod.POST)public ResponseEntity<String> uploadFile (@RequestParam("file") MultipartFile file){String result ;try{String path = fileDfsUtil.upload(file) ;if (!StringUtils.isEmpty(path)){result = path ;} else {result = "上传失败" ;}} catch (Exception e){e.printStackTrace() ;result = "服务异常" ;}return ResponseEntity.ok(result);}/*** 文件删除*/@RequestMapping(value = "https://www.huyubaike.com/deleteByPath", method = RequestMethod.GET)public ResponseEntity<String> deleteByPath (){String filePathName = "group1/M00/00/00/rBIAAmNmi82AJxLsAABdrZgsqUU214.jpg" ;fileDfsUtil.deleteFile(filePathName);return ResponseEntity.ok("SUCCESS") ;}}5.4 接口演示
- 访问页面:http://localhost:8081/fdfs-demo/swagger-ui.html

文章插图
- 测试接口
- 上传接口
- 删除接口
经验总结扩展阅读
- 海螺哪里不能吃
- 西瓜切开了可以隔夜第二天吃吗
- 上古卷轴5怎样结婚(上古卷轴5第一美女)
- 2022年第22号台风“尼格”在西北太平洋洋面上生成
- 火车站行李托运流程
- 西兰花怎么吃
- 2023年出伏时间 2023年初伏第一天是几月几号
- 奥比岛暗夜袭击第一轮金块失踪之谜通关攻略
- 纸嫁衣4第一章圆珠笔怎么获取以及有什么用
- 火锅底料可以吃第二次吗
