Commit f7e15fdf by 阳浪

文件上传

parent e3890bda
......@@ -4,6 +4,7 @@ import com.yizhi.aliyun.application.util.PropertiesUtil;
import com.yizhi.core.application.file.util.MinioTools;
import com.yizhi.util.application.domain.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -22,14 +23,18 @@ public class FileUploadController {
@Autowired
PropertiesUtil propertiesUtil;
@Value("${pc.host.url}")
String pcHostUrl;
@PostMapping("/upload")
public Response<String> uploadFile(@RequestParam("file") MultipartFile file,@RequestParam("Filename")String Filename) {
try {
String[] fileNames = Filename.split("/");;
String bucketName =fileNames[0];
minioTools.uplodFile(bucketName,fileNames[1],file.getInputStream());
return Response.ok(minioTools.getFile(bucketName,fileNames[1]));
String name = 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) {
return Response.fail("Could not upload the file: " + Filename);
}
......
......@@ -38,6 +38,9 @@ public class PolicyController {
@Value("${ACTIVE}")
public String active;
@Value("${pc.host.url}")
String pcHostUrl;
@Autowired
PropertiesUtil propertiesUtil;
......@@ -81,32 +84,32 @@ public class PolicyController {
}
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 {
// long expireTime = 60 * 24;
// long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
// Date expiration = new Date(expireEndTime);
// PolicyConditions policyConds = new PolicyConditions();
// policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10485760000L);
// policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
long expireTime = 60 * 24;
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
Date expiration = new Date(expireEndTime);
PolicyConditions policyConds = new PolicyConditions();
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10485760000L);
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
// String postPolicy = client.generatePostPolicy(expiration, policyConds);
// byte[] binaryData = postPolicy.getBytes("utf-8");
// String encodedPolicy = BinaryUtil.toBase64String(binaryData);
// String postSignature = client.calculatePostSignature(postPolicy);
String postPolicy = client.generatePostPolicy(expiration, policyConds);
byte[] binaryData = postPolicy.getBytes("utf-8");
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
String postSignature = client.calculatePostSignature(postPolicy);
Map<String, String> respMap = new LinkedHashMap<String, String>();
respMap.put("accessid", accessId);
respMap.put("policy", "encodedPolicy");
respMap.put("signature", "postSignature");
respMap.put("expire", "formatISO8601Date(expiration)");
respMap.put("policy", encodedPolicy);
respMap.put("signature", postSignature);
//respMap.put("expire", formatISO8601Date(expiration));
respMap.put("dir", dir);
respMap.put("host", host);
respMap.put("expire", "String.valueOf(expireEndTime / 1000)");
respMap.put("expire", String.valueOf(expireEndTime / 1000));
respMap.put("active", active);
JSONObject ja1 = JSONObject.fromObject(respMap);
System.out.println(ja1.toString());
......@@ -115,7 +118,7 @@ public class PolicyController {
} catch (Exception e) {
return Response.fail(e.getMessage());
} 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