|
@@ -1,9 +1,57 @@
|
|
|
package com.jpsoft.picc.modules.auth.controller;
|
|
|
|
|
|
+import com.alibaba.druid.util.StringUtils;
|
|
|
+import com.jpsoft.picc.modules.common.config.OSSConfig;
|
|
|
+import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.picc.modules.common.utils.Uploader;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+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.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
@Api(description="附件管理")
|
|
|
@RestController
|
|
|
+@RequestMapping("/auth/attachment")
|
|
|
+@Slf4j
|
|
|
public class AttachmentController {
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
+ @PostMapping("upload")
|
|
|
+ @ApiOperation(value="附件上传")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "fileName",value = "文件名", required = false, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subFolder",value = "子目录名(如/test)", required = false, paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> upload(String fileName,String subFolder,MultipartFile uploadFile){
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(fileName)){
|
|
|
+ fileName = uploadFile.getOriginalFilename();
|
|
|
+ }
|
|
|
+
|
|
|
+ String retFileUrl = Uploader.ossUpload(ossConfig,subFolder,fileName,uploadFile.getInputStream());
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setData(retFileUrl);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
}
|