package com.kidgrow.filecenter.controller;
|
|
import com.kidgrow.common.model.PageResult;
|
import com.kidgrow.common.model.Result;
|
import com.kidgrow.filecenter.model.FileInfo;
|
import com.kidgrow.filecenter.service.IFileService;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import java.util.Map;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: 文件上传<br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/2/18 11:41 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
@RestController
|
public class FileController {
|
@Resource
|
private IFileService fileService;
|
|
/**
|
* 文件上传
|
* 根据fileType选择上传方式
|
*
|
* @param file
|
* @return
|
* @throws Exception
|
*/
|
@PostMapping(value="/files-anon",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
public FileInfo upload(@RequestParam("file") MultipartFile file) throws Exception {
|
return fileService.upload(file);
|
}
|
|
|
/**
|
* 文件上传
|
* 根据fileType选择上传方式
|
*
|
* @param file
|
* @return
|
* @throws Exception
|
*/
|
@PostMapping(value="/files-upload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
public FileInfo feignUpload(@RequestPart("file") MultipartFile file,@RequestParam String imgType) throws Exception {
|
return fileService.upload(file,imgType);
|
}
|
/**
|
* 文件上传 返回带缩略图地址的对象,缩略图在path字段
|
*
|
* @param file
|
* @return
|
* @throws Exception
|
*/
|
@PostMapping(value="/files-thupload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
public FileInfo thUpload(@RequestPart("file") MultipartFile file,@RequestParam String imgType) throws Exception {
|
return fileService.uploadForThumbnails(file,imgType);
|
}
|
|
/**
|
* 文件删除
|
*
|
* @param id
|
*/
|
@DeleteMapping("/files/{id}")
|
public Result delete(@PathVariable String id) {
|
try {
|
fileService.delete(id);
|
return Result.succeed("操作成功");
|
} catch (Exception ex) {
|
return Result.failed("操作失败");
|
}
|
}
|
|
/**
|
* 文件查询
|
*
|
* @param params
|
* @return
|
*/
|
@GetMapping("/files")
|
public PageResult<FileInfo> findFiles(@RequestParam Map<String, Object> params) {
|
return fileService.findList(params);
|
}
|
}
|