|
@@ -1,11 +1,13 @@
|
|
|
package edu.travel.upload.web;
|
|
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
import com.obs.services.ObsClient;
|
|
|
import com.obs.services.model.*;
|
|
|
import edu.travel.remote.upload.UploadRemoteController;
|
|
|
import edu.travel.remote.upload.dto.EduFileBlobDTO;
|
|
|
import edu.travel.remote.upload.dto.EduFileDTO;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import edu.travel.upload.config.MD5Calculator;
|
|
|
import edu.travel.upload.entity.EduFile;
|
|
|
import edu.travel.upload.entity.EduFileBlob;
|
|
|
import edu.travel.upload.obs.property.ObsProperties;
|
|
@@ -80,6 +82,11 @@ public class UploadController implements UploadRemoteController {
|
|
|
@PostMapping(value = "/uploadBlob",headers = {"content-type=multipart/form-data"})
|
|
|
@PreAuthorize("permitAll()")
|
|
|
public RPCBaseResponse uploadBigFile(EduFileBlobDTO eduFileBlob, MultipartFile file) throws IOException {
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ String calculateMD5 = MD5Calculator.calculateMD5(bytes);
|
|
|
+ if (!eduFileBlob.getBlobMd5().equals(calculateMD5)) {
|
|
|
+ return RPCBaseResponse.error("分片md5不一致");
|
|
|
+ }
|
|
|
EduFileBlob fileBlob = new EduFileBlob();
|
|
|
BeanUtils.copyProperties(eduFileBlob, fileBlob);
|
|
|
boolean exists = obsClient.headBucket(obsProperties.getBucketName());
|
|
@@ -88,6 +95,7 @@ public class UploadController implements UploadRemoteController {
|
|
|
HeaderResponse response = obsClient.createBucket(obsProperties.getBucketName());
|
|
|
logger.info("创建桶成功" + response.getRequestId());
|
|
|
}
|
|
|
+
|
|
|
obsClient.putObject(obsProperties.getBucketName(),"/service/chunk/"+eduFileBlob.getUploadId()+"/"+fileBlob.getBlobNum(),file.getInputStream());
|
|
|
boolean save = eduFileBlobService.save(fileBlob);
|
|
|
if (save){
|
|
@@ -127,6 +135,11 @@ public class UploadController implements UploadRemoteController {
|
|
|
@PostMapping(value = "/upload",headers = {"content-type=multipart/form-data"})
|
|
|
@PreAuthorize("permitAll()")
|
|
|
public RPCBaseResponse uploadFile(EduFileDTO eduFile,MultipartFile file) throws IOException {
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ String calculateMD5 = MD5Calculator.calculateMD5(bytes);
|
|
|
+ if (!eduFile.getFileMd5().equals(calculateMD5)) {
|
|
|
+ return RPCBaseResponse.error("md5不一致");
|
|
|
+ }
|
|
|
PutObjectResult putObjectResult = obsClient.putObject(obsProperties.getBucketName(), "/service/chunk/" + eduFile.getUploadId() + "/" + file.getOriginalFilename(), file.getInputStream());
|
|
|
String objectUrl = putObjectResult.getObjectUrl();
|
|
|
EduFile files = new EduFile();
|