通过url上传文件-加上style
This commit is contained in:
parent
7d3ef9fee9
commit
ab70de2769
@ -145,6 +145,6 @@ public class ServerFileController implements ServerFileServiceApi {
|
||||
// 获取feign调用请求头携带的用户信息
|
||||
String contextInfoLiteJsonStr = httpServletRequest.getHeader("X-CONTEXT-INFO-LITE");
|
||||
ContextInfo.LiteSaasContext liteSaasContext = JSONUtil.toBean(contextInfoLiteJsonStr, ContextInfo.LiteSaasContext.class);
|
||||
return CommonResponse.success(BeanConverter.convert(fileByUrlService.uploadByUrl(dto.getAppCode(), dto.getBizScene(), dto.getFileName(), dto.getFileUrl(), dto.getChannelCode(), liteSaasContext), ServerFileUploadResponse.class));
|
||||
return CommonResponse.success(BeanConverter.convert(fileByUrlService.uploadByUrl(dto.getAppCode(), dto.getBizScene(), dto.getFileName(), dto.getFileUrl(), dto.getChannelCode(), dto.getStyle(), liteSaasContext), ServerFileUploadResponse.class));
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,5 +27,9 @@ public class ServerFileUploadByUrlRequest {
|
||||
private String fileUrl;
|
||||
|
||||
private Integer channelCode;
|
||||
/**
|
||||
* 图片样式,比如x-oss-process=image/auto-orient,1/resize,p_50/quality,q_30
|
||||
*/
|
||||
private String style;
|
||||
|
||||
}
|
||||
|
||||
@ -25,4 +25,9 @@ public class ServerFileUploadByUrlDto {
|
||||
private String filePath;
|
||||
private Integer channelCode;
|
||||
|
||||
/**
|
||||
* 图片样式,比如x-oss-process=image/auto-orient,1/resize,p_50/quality,q_30
|
||||
*/
|
||||
private String style;
|
||||
|
||||
}
|
||||
|
||||
@ -37,5 +37,5 @@ public interface FileByUrlService {
|
||||
/**
|
||||
* 上传-通过url
|
||||
*/
|
||||
ServerFileUploadResponse uploadByUrl(String appCode, String bizScene, String fileName, String url,Integer channelType, ContextInfo.LiteSaasContext liteSaasContext);
|
||||
ServerFileUploadResponse uploadByUrl(String appCode, String bizScene, String fileName, String url,Integer channelType, String style, ContextInfo.LiteSaasContext liteSaasContext);
|
||||
}
|
||||
|
||||
@ -132,11 +132,11 @@ public class FileByUrlServiceImpl implements FileByUrlService {
|
||||
* 通过url上传
|
||||
*/
|
||||
@Override
|
||||
public ServerFileUploadResponse uploadByUrl(String appCode, String bizScene, String fileName, String url, Integer channelType, ContextInfo.LiteSaasContext liteSaasContext) {
|
||||
public ServerFileUploadResponse uploadByUrl(String appCode, String bizScene, String fileName, String url, Integer channelType,String style, ContextInfo.LiteSaasContext liteSaasContext) {
|
||||
log.info("uploadByUrl params,appCode:{},bizScene:{}, fileName:{},url:{},channelType:{}", appCode, bizScene, fileName, url, channelType);
|
||||
Long start = System.currentTimeMillis();
|
||||
//重新构建链接
|
||||
url = this.rebuildUrl(url);
|
||||
url = this.rebuildUrl(url, style);
|
||||
File ossFile = uploadFileAndGetFile(appCode, bizScene, fileName, url, channelType);
|
||||
//操作日志记录
|
||||
operateLog(this.buildUploadParams(appCode, bizScene, fileName, url, channelType), "", FILE_UPLOAD_CODE, FILE_UPLOAD_NAME, liteSaasContext);
|
||||
@ -150,13 +150,13 @@ public class FileByUrlServiceImpl implements FileByUrlService {
|
||||
* url:https://xxx,则直接返回
|
||||
* url:fileKey,则返回https://链接
|
||||
*/
|
||||
private String rebuildUrl(String url) {
|
||||
private String rebuildUrl(String url, String style) {
|
||||
if (StringUtils.isNotBlank(url)) {
|
||||
FindFileUrlDto findFileUrlDto = FindFileUrlDto.builder().fileKey(Lists.newArrayList(url)).build();
|
||||
SignUrlDownloadDto signUrlDownloadDto = SignUrlDownloadDto.builder().fileKeys(Lists.newArrayList(url)).style(style).build();
|
||||
|
||||
List<FindFileUrlResponse> responseList = fileService.findFileUrl(findFileUrlDto);
|
||||
List<SignUrlDownloadResponse> responseList = fileService.signUrlDownload(signUrlDownloadDto);
|
||||
if (CollectionUtil.isNotEmpty(responseList)) {
|
||||
return responseList.get(0).getUrl();
|
||||
return responseList.get(0).getSignUrl();
|
||||
}
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
|
||||
@ -942,7 +942,7 @@ public class FileServiceImpl implements FileService {
|
||||
if (CollectionUtil.isEmpty(map)) {
|
||||
return httpUrlList.stream().map(item -> SignUrlDownloadResponse.builder().fileKey(item).signUrl(item).build()).collect(Collectors.toList());
|
||||
}
|
||||
List<SignUrlDownloadResponse> responseList = this.buildFileKeyResponse(Lists.newArrayList(map.values()), null, null);
|
||||
List<SignUrlDownloadResponse> responseList = this.buildFileKeyResponse(Lists.newArrayList(map.values()), null, dto.getStyle());
|
||||
if (CollectionUtil.isEmpty(responseList)) {
|
||||
return httpUrlList.stream().map(item -> SignUrlDownloadResponse.builder().fileKey(item).signUrl(item).build()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user