|
@@ -3,8 +3,6 @@ package com.backendsys.modules.sdk.tencentcloud.cos.service.impl;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.crypto.digest.DigestUtil;
|
|
|
-import cn.hutool.http.HttpUtil;
|
|
|
import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
|
import com.backendsys.modules.common.utils.CommonUtil;
|
|
@@ -32,18 +30,14 @@ import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URL;
|
|
|
-import java.nio.file.Path;
|
|
|
-import java.nio.file.Paths;
|
|
|
import java.util.Date;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
// 图片处理概述
|
|
|
// https://cloud.tencent.com/document/product/436/42215
|
|
@@ -83,24 +77,10 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
}
|
|
|
|
|
|
// [腾讯云COS][高级接口] 获取进度函数
|
|
|
- private void showTransferProgress(String filename, Transfer transfer) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 为什么 urlToCos 这里拿不到 Token?
|
|
|
-
|
|
|
- Long user_id = SecurityUtil.getUserId();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ private void showTransferProgress(String filename, Transfer transfer, Long input_user_id) {
|
|
|
|
|
|
+ Long user_id = input_user_id == null ? SecurityUtil.getUserId() : input_user_id;
|
|
|
+ System.out.println("showTransferProgress (user_id): " + user_id);
|
|
|
|
|
|
// [SSE] 进度回传
|
|
|
Progress progress = new Progress();
|
|
@@ -195,7 +175,7 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
// 高级上传
|
|
|
TransferManager transferManager = TencentCosUtil.createTransferManager(cosClient);
|
|
|
Upload upload = transferManager.upload(putObjectRequest); // 返回一个异步结果Upload
|
|
|
- showTransferProgress(filename, upload); // 查询上传进度,直到上传结束
|
|
|
+ showTransferProgress(filename, upload, null); // 查询上传进度,直到上传结束
|
|
|
UploadResult uploadResult = upload.waitForUploadResult(); // 捕获可能出现的异常
|
|
|
|
|
|
// 自定义返回结果实体
|
|
@@ -380,9 +360,12 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
public SysFileResult urlToCOS(String url) {
|
|
|
return urlToCOS(url, null);
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public SysFileResult urlToCOS(String url, String input_suffix) {
|
|
|
+ return urlToCOS(url, input_suffix);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public SysFileResult urlToCOS(String url, String input_suffix, Long user_id) {
|
|
|
|
|
|
if (StrUtil.isEmpty(url)) throw new CustException("url 不能为空");
|
|
|
|
|
@@ -408,7 +391,7 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
// 高级上传
|
|
|
TransferManager transferManager = TencentCosUtil.createTransferManager(cosClient);
|
|
|
Upload upload = transferManager.upload(putObjectRequest); // 返回一个异步结果Upload
|
|
|
- showTransferProgress(object_filename, upload); // 查询上传进度,直到上传结束
|
|
|
+ showTransferProgress(object_filename, upload, user_id); // 查询上传进度,直到上传结束
|
|
|
UploadResult uploadResult = upload.waitForUploadResult(); // 捕获可能出现的异常
|
|
|
|
|
|
SysFileResult result = new SysFileResult();
|
|
@@ -428,4 +411,5 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
if (cosClient != null) cosClient.shutdown();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|