Commit f7e15fdf by 阳浪

文件上传

parent e3890bda
...@@ -4,6 +4,7 @@ import com.yizhi.aliyun.application.util.PropertiesUtil; ...@@ -4,6 +4,7 @@ import com.yizhi.aliyun.application.util.PropertiesUtil;
import com.yizhi.core.application.file.util.MinioTools; import com.yizhi.core.application.file.util.MinioTools;
import com.yizhi.util.application.domain.Response; import com.yizhi.util.application.domain.Response;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -22,14 +23,18 @@ public class FileUploadController { ...@@ -22,14 +23,18 @@ public class FileUploadController {
@Autowired @Autowired
PropertiesUtil propertiesUtil; PropertiesUtil propertiesUtil;
@Value("${pc.host.url}")
String pcHostUrl;
@PostMapping("/upload") @PostMapping("/upload")
public Response<String> uploadFile(@RequestParam("file") MultipartFile file,@RequestParam("Filename")String Filename) { public Response<String> uploadFile(@RequestParam("file") MultipartFile file,@RequestParam("Filename")String Filename) {
try { try {
String[] fileNames = Filename.split("/");; String[] fileNames = Filename.split("/");;
String bucketName =fileNames[0]; String bucketName =fileNames[0];
minioTools.uplodFile(bucketName,fileNames[1],file.getInputStream()); String name = fileNames[1];
return Response.ok(minioTools.getFile(bucketName,fileNames[1])); minioTools.uplodFile(bucketName,name,file.getInputStream());
return Response.ok(pcHostUrl+"/api/v1/buckets/"+bucketName+"/objects/download/?preview=true&prefix="+name);
} catch (IOException ex) { } catch (IOException ex) {
return Response.fail("Could not upload the file: " + Filename); return Response.fail("Could not upload the file: " + Filename);
} }
......
...@@ -38,6 +38,9 @@ public class PolicyController { ...@@ -38,6 +38,9 @@ public class PolicyController {
@Value("${ACTIVE}") @Value("${ACTIVE}")
public String active; public String active;
@Value("${pc.host.url}")
String pcHostUrl;
@Autowired @Autowired
PropertiesUtil propertiesUtil; PropertiesUtil propertiesUtil;
...@@ -81,32 +84,32 @@ public class PolicyController { ...@@ -81,32 +84,32 @@ public class PolicyController {
} }
String host = "https://" + bucket + "." + endpoint; String host = "https://" + bucket + "." + endpoint;
//String host = pcHostUrl+"/api/v1/buckets/"+dir+"/objects/download/?preview=true&prefix=";
OSSClient client = new OSSClient(endpoint, accessId, accessKey);
// OSSClient client = new OSSClient(endpoint, accessId, accessKey);
try { try {
// long expireTime = 60 * 24; long expireTime = 60 * 24;
// long expireEndTime = System.currentTimeMillis() + expireTime * 1000; long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
// Date expiration = new Date(expireEndTime); Date expiration = new Date(expireEndTime);
// PolicyConditions policyConds = new PolicyConditions(); PolicyConditions policyConds = new PolicyConditions();
// policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10485760000L); policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10485760000L);
// policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir); policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
// String postPolicy = client.generatePostPolicy(expiration, policyConds); String postPolicy = client.generatePostPolicy(expiration, policyConds);
// byte[] binaryData = postPolicy.getBytes("utf-8"); byte[] binaryData = postPolicy.getBytes("utf-8");
// String encodedPolicy = BinaryUtil.toBase64String(binaryData); String encodedPolicy = BinaryUtil.toBase64String(binaryData);
// String postSignature = client.calculatePostSignature(postPolicy); String postSignature = client.calculatePostSignature(postPolicy);
Map<String, String> respMap = new LinkedHashMap<String, String>(); Map<String, String> respMap = new LinkedHashMap<String, String>();
respMap.put("accessid", accessId); respMap.put("accessid", accessId);
respMap.put("policy", "encodedPolicy"); respMap.put("policy", encodedPolicy);
respMap.put("signature", "postSignature"); respMap.put("signature", postSignature);
respMap.put("expire", "formatISO8601Date(expiration)"); //respMap.put("expire", formatISO8601Date(expiration));
respMap.put("dir", dir); respMap.put("dir", dir);
respMap.put("host", host); respMap.put("host", host);
respMap.put("expire", "String.valueOf(expireEndTime / 1000)"); respMap.put("expire", String.valueOf(expireEndTime / 1000));
respMap.put("active", active); respMap.put("active", active);
JSONObject ja1 = JSONObject.fromObject(respMap); JSONObject ja1 = JSONObject.fromObject(respMap);
System.out.println(ja1.toString()); System.out.println(ja1.toString());
...@@ -115,7 +118,7 @@ public class PolicyController { ...@@ -115,7 +118,7 @@ public class PolicyController {
} catch (Exception e) { } catch (Exception e) {
return Response.fail(e.getMessage()); return Response.fail(e.getMessage());
} finally { } finally {
// client.shutdown(); client.shutdown();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment