|
|
@@ -1,26 +1,25 @@
|
|
|
package com.uas.platform.b2c.common.base.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.dfs.domain.FileInfo;
|
|
|
import com.uas.dfs.domain.MetaData;
|
|
|
import com.uas.dfs.service.FileClient;
|
|
|
import com.uas.platform.b2c.common.base.constant.FileClientConstant;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
+import com.uas.ps.core.page.exception.IllegalOperatorException;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.io.ByteArrayResource;
|
|
|
-import org.springframework.http.*;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.LinkedMultiValueMap;
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.io.*;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
@Service
|
|
|
public class FileClientImpl implements FileClient {
|
|
|
|
|
|
@@ -30,44 +29,55 @@ public class FileClientImpl implements FileClient {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(FileClientImpl.class);
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MinioClientImpl minioClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
public FileClientImpl(RestTemplate restTemplate, SysConf sysConf) {
|
|
|
this.restTemplate = restTemplate;
|
|
|
this.sysConf = sysConf;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public String upload(byte[] bytes, long l, final String s, Set<MetaData> set) {
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- MediaType type = MediaType.parseMediaType("multipart/form-data;charset=UTF-8");
|
|
|
- headers.setContentType(type);
|
|
|
-
|
|
|
- File file = new File(s);
|
|
|
try {
|
|
|
- OutputStream output = new FileOutputStream(file);
|
|
|
- BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);
|
|
|
- bufferedOutput.write(bytes);
|
|
|
- } catch (IOException e) {
|
|
|
+ return minioClient.upload(new ByteArrayInputStream(bytes), Integer.valueOf(String.valueOf(l)), s);
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new IllegalOperatorException("附件上传失败");
|
|
|
}
|
|
|
|
|
|
- MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
|
|
|
- ByteArrayResource arrayResource = new ByteArrayResource(bytes){
|
|
|
- @Override
|
|
|
- public String getFilename() throws IllegalStateException {
|
|
|
- return "test." + s;
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
- form.add("file", arrayResource);
|
|
|
- HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(form, headers);
|
|
|
- ResponseEntity<JSONObject> responseEntity = null;
|
|
|
- try {
|
|
|
- responseEntity = restTemplate.postForEntity(sysConf.getUploadFileUrl() + FileClientConstant.FILE_UPLOAD, requestEntity, JSONObject.class);
|
|
|
- }catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return responseEntity.getBody().getString("path");
|
|
|
+// HttpHeaders headers = new HttpHeaders();
|
|
|
+// MediaType type = MediaType.parseMediaType("multipart/form-data;charset=UTF-8");
|
|
|
+// headers.setContentType(type);
|
|
|
+//
|
|
|
+// File file = new File(s);
|
|
|
+// try {
|
|
|
+// OutputStream output = new FileOutputStream(file);
|
|
|
+// BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);
|
|
|
+// bufferedOutput.write(bytes);
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+//
|
|
|
+// MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
|
|
|
+// ByteArrayResource arrayResource = new ByteArrayResource(bytes){
|
|
|
+// @Override
|
|
|
+// public String getFilename() throws IllegalStateException {
|
|
|
+// return "test." + s;
|
|
|
+// }
|
|
|
+//
|
|
|
+// };
|
|
|
+// form.add("file", arrayResource);
|
|
|
+// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(form, headers);
|
|
|
+// ResponseEntity<JSONObject> responseEntity = null;
|
|
|
+// try {
|
|
|
+// responseEntity = restTemplate.postForEntity(sysConf.getUploadFileUrl() + FileClientConstant.FILE_UPLOAD, requestEntity, JSONObject.class);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// return responseEntity.getBody().getString("path");
|
|
|
}
|
|
|
|
|
|
@Override
|