|
@@ -1,20 +1,21 @@
|
|
|
package cn.com.qmth.examcloud.exchange.inner.api.provider;
|
|
|
|
|
|
-import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
-import org.apache.commons.fileupload.disk.DiskFileItem;
|
|
|
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.commons.CommonsMultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.AES;
|
|
|
import cn.com.qmth.examcloud.exchange.inner.api.UpyunCloudService;
|
|
|
import cn.com.qmth.examcloud.exchange.inner.api.request.PutFileReq;
|
|
|
import cn.com.qmth.examcloud.exchange.inner.api.response.PutFileResp;
|
|
|
import cn.com.qmth.examcloud.exchange.inner.service.UpyunService;
|
|
|
import cn.com.qmth.examcloud.exchange.inner.service.bean.UpyunPathEnvironmentInfo;
|
|
|
+import cn.com.qmth.examcloud.web.config.SystemConfig;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
|
|
|
/**
|
|
@@ -33,23 +34,31 @@ public class UpyunCloudServiceProvider extends ControllerSupport implements Upyu
|
|
|
@Autowired
|
|
|
UpyunService upyunService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SystemConfig systemConfig;
|
|
|
+
|
|
|
AES aes = new AES();
|
|
|
|
|
|
@PostMapping("putFile")
|
|
|
- public PutFileResp putFile(PutFileReq req, CommonsMultipartFile file) {
|
|
|
+ @Override
|
|
|
+ public PutFileResp putFile(PutFileReq req) {
|
|
|
String fileSuffix = req.getFileSuffix();
|
|
|
Long rootOrgId = req.getRootOrgId();
|
|
|
Long userId = req.getUserId();
|
|
|
String siteId = req.getSiteId();
|
|
|
- DiskFileItem item = (DiskFileItem) file.getFileItem();
|
|
|
- File storeLocation = item.getStoreLocation();
|
|
|
+ MultipartFile mf = req.getFile();
|
|
|
|
|
|
UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
|
|
|
env.setRootOrgId(String.valueOf(rootOrgId));
|
|
|
env.setUserId(String.valueOf(userId));
|
|
|
env.setFileSuffix(fileSuffix);
|
|
|
|
|
|
- String url = upyunService.writeFile(siteId, env, storeLocation);
|
|
|
+ String url = null;
|
|
|
+ try {
|
|
|
+ url = upyunService.writeFile(siteId, env, mf.getInputStream());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new StatusException("005001", "fail to write to upyun", e);
|
|
|
+ }
|
|
|
url = aes.encrypt(url);
|
|
|
|
|
|
PutFileResp resp = new PutFileResp();
|