腾讯云对象存储-后台-文件名校验
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package com.accompany.common.tencent.cos;
|
||||
|
||||
import com.accompany.common.config.TencentCosConfig;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.UUIDUtil;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.model.PutObjectRequest;
|
||||
import com.qcloud.cos.model.PutObjectResult;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -24,9 +26,10 @@ public class TencentCosUploadService {
|
||||
|
||||
@SneakyThrows
|
||||
public String uploadByStream(InputStream is, String fileName) {
|
||||
if (!StringUtils.hasText(fileName)){
|
||||
fileName = UUIDUtil.get();
|
||||
if (StringUtils.isBlank(fileName)){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
|
||||
PutObjectRequest request = new PutObjectRequest(config.getBucket(), fileName, is, null);
|
||||
PutObjectResult result = client.putObject(request);
|
||||
log.info("[腾讯云cos] {} 上传成功, requestId {}", fileName, result.getRequestId());
|
||||
|
Reference in New Issue
Block a user