同步代码
This commit is contained in:
@@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.dromara.common.core.enums.ContentTypeEnum;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.Base64Utils;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
@@ -68,16 +69,33 @@ public class RemoteFileServiceImpl implements RemoteFileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteFile upload(byte[] file) throws ServiceException {
|
||||
// 计算文件类型
|
||||
String type = Base64Utils.getType(file);
|
||||
// 获contentType
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
public RemoteFile uploadImg(byte[] file) throws ServiceException {
|
||||
try {
|
||||
// 计算文件类型
|
||||
String type = Base64Utils.getType(file);
|
||||
// 获contentType
|
||||
ContentTypeEnum contentTypeEnum = ContentTypeEnum.ContentTypeEnum(type);
|
||||
OssClient storage = OssFactory.instance();
|
||||
UploadResult uploadResult = storage.uploadSuffix(file, type, contentTypeEnum.getContentType());
|
||||
// 保存文件信息
|
||||
SysOssBo oss = new SysOssBo();
|
||||
oss.setUrl(uploadResult.getUrl());
|
||||
oss.setFileSuffix(type);
|
||||
oss.setFileName(uploadResult.getFilename());
|
||||
oss.setOriginalName(uploadResult.getFilename());
|
||||
oss.setService(storage.getConfigKey());
|
||||
sysOssService.insertByBo(oss);
|
||||
RemoteFile sysFile = new RemoteFile();
|
||||
sysFile.setOssId(oss.getOssId());
|
||||
sysFile.setName(uploadResult.getFilename());
|
||||
sysFile.setUrl(uploadResult.getUrl());
|
||||
sysFile.setOriginalName(uploadResult.getFilename());
|
||||
sysFile.setFileSuffix(type);
|
||||
return sysFile;
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件失败", e);
|
||||
throw new ServiceException("上传文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user