|
@@ -8,13 +8,22 @@
|
|
package cn.com.qmth.examcloud.core.print.api.controller;
|
|
package cn.com.qmth.examcloud.core.print.api.controller;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
|
+import cn.com.qmth.examcloud.core.print.common.Result;
|
|
|
|
+import cn.com.qmth.examcloud.core.print.common.upyun.UpYunClient;
|
|
import cn.com.qmth.examcloud.core.print.common.upyun.UpYunProperty;
|
|
import cn.com.qmth.examcloud.core.print.common.upyun.UpYunProperty;
|
|
|
|
+import cn.com.qmth.examcloud.core.print.common.utils.Check;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 文件上传相关接口
|
|
* 文件上传相关接口
|
|
@@ -26,13 +35,29 @@ import org.springframework.web.bind.annotation.RestController;
|
|
@Api(tags = "文件上传相关接口")
|
|
@Api(tags = "文件上传相关接口")
|
|
@RequestMapping("${$rmp.ctrl.print}/upload")
|
|
@RequestMapping("${$rmp.ctrl.print}/upload")
|
|
public class UploadController extends ControllerSupport {
|
|
public class UploadController extends ControllerSupport {
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(UploadController.class);
|
|
@Autowired
|
|
@Autowired
|
|
- private UpYunProperty upYunProperty;
|
|
|
|
|
|
+ private UpYunClient upYunClient;
|
|
|
|
+
|
|
|
|
+ @PostMapping
|
|
|
|
+ @ApiOperation(value = "上传文件")
|
|
|
|
+ public Result upload(HttpServletRequest request) throws Exception {
|
|
|
|
+ MultipartFile file = null;
|
|
|
|
+ try {
|
|
|
|
+ //暂时只支持单文件上传,默认处理一个文件
|
|
|
|
+ file = ((MultipartHttpServletRequest) request).getFile("file");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.warn(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ Check.isNull(file, "上传的文件不能为空!");
|
|
|
|
+ Check.isTrue(file.isEmpty(), "上传的文件不能为空!");
|
|
|
|
+ return upYunClient.upload(file.getBytes(), file.getOriginalFilename());
|
|
|
|
+ }
|
|
|
|
|
|
@PostMapping("/upyun/info")
|
|
@PostMapping("/upyun/info")
|
|
@ApiOperation(value = "获取又拍云信息")
|
|
@ApiOperation(value = "获取又拍云信息")
|
|
public UpYunProperty getUpYunInfo() {
|
|
public UpYunProperty getUpYunInfo() {
|
|
- return upYunProperty;
|
|
|
|
|
|
+ return upYunClient.getProperty();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|