Commit e3890bda by 阳浪

收藏

parent 10faa87d
package com.yizhi.aliyun.application.controller;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@RestController
@RequestMapping("/api")
public class FileUploadController {
@Autowired
private MinioTools minioTools;
@Autowired
PropertiesUtil propertiesUtil;
@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]));
} catch (IOException ex) {
return Response.fail("Could not upload the file: " + Filename);
}
}
}
\ No newline at end of file
...@@ -83,30 +83,30 @@ public class PolicyController { ...@@ -83,30 +83,30 @@ public class PolicyController {
String host = "https://" + bucket + "." + endpoint; String host = "https://" + bucket + "." + endpoint;
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 +115,7 @@ public class PolicyController { ...@@ -115,7 +115,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