|
@@ -6,7 +6,6 @@ import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
@@ -16,6 +15,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.file.entity.*;
|
|
|
import com.fjhx.file.mapper.FileInfoMapper;
|
|
|
import com.fjhx.file.service.FileInfoService;
|
|
|
+import com.fjhx.file.utils.TencentCosUtils;
|
|
|
import com.obs.services.ObsClient;
|
|
|
import com.obs.services.model.PutObjectRequest;
|
|
|
import com.ruoyi.common.constant.BaseSourceConstant;
|
|
@@ -54,6 +54,9 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
@Value("${obs.url}")
|
|
|
private String url;
|
|
|
|
|
|
+ @Value("${obs.type}")
|
|
|
+ private String type;
|
|
|
+
|
|
|
@Value("${obs.bucketName}")
|
|
|
private String bucketName;
|
|
|
|
|
@@ -94,13 +97,13 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
// // 获取签名
|
|
|
// PostSignatureRequest request = new PostSignatureRequest(currentTimeMillis, bucketName, objectKey);
|
|
|
// PostSignatureResponse temporarySignature = obsClient.createPostSignature(request);
|
|
|
- // 封装签名
|
|
|
- Map<String, String> body = new LinkedHashMap<>();
|
|
|
+ // 封装签名
|
|
|
+ Map<String, String> body = new LinkedHashMap<>();
|
|
|
// body.put("policy", temporarySignature.getPolicy());
|
|
|
- body.put("AccessKeyId", ak);
|
|
|
+// body.put("AccessKeyId", ak);
|
|
|
// body.put("signature", temporarySignature.getSignature());
|
|
|
- body.put("key", objectKey);
|
|
|
- singVo.setUploadBody(body);
|
|
|
+ body.put("key", objectKey);
|
|
|
+ singVo.setUploadBody(body);
|
|
|
//
|
|
|
// } catch (Exception e) {
|
|
|
// throw new ServiceException("获取签名失败");
|
|
@@ -129,19 +132,28 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
MultipartFile file = uploadBody.getFile();
|
|
|
String objectKey = uploadBody.getKey();
|
|
|
|
|
|
- ObsClient obsClient = getObsClient();
|
|
|
- try {
|
|
|
- PutObjectRequest putObjectRequest = new PutObjectRequest();
|
|
|
- putObjectRequest.setBucketName(bucketName);
|
|
|
- putObjectRequest.setObjectKey(objectKey);
|
|
|
- putObjectRequest.setInput(file.getInputStream());
|
|
|
- obsClient.putObject(putObjectRequest);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- throw new ServiceException("文件上传失败!");
|
|
|
- } finally {
|
|
|
- IoUtil.close(obsClient);
|
|
|
+
|
|
|
+ //腾讯云COS对象存储
|
|
|
+ if (Objects.equals(type, "tencent")) {
|
|
|
+ TencentCosUtils.uploadFile(ak, sk, bucketName, objectKey, file);
|
|
|
}
|
|
|
+ //华为云OBS对象存储(默认)
|
|
|
+ else if (Objects.equals(type, "huawei")) {
|
|
|
+ ObsClient obsClient = getObsClient();
|
|
|
+ try {
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest();
|
|
|
+ putObjectRequest.setBucketName(bucketName);
|
|
|
+ putObjectRequest.setObjectKey(objectKey);
|
|
|
+ putObjectRequest.setInput(file.getInputStream());
|
|
|
+ obsClient.putObject(putObjectRequest);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ throw new ServiceException("华为云 文件上传失败!");
|
|
|
+ } finally {
|
|
|
+ IoUtil.close(obsClient);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@DS(BaseSourceConstant.BASE)
|