mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
基础设施:前端直连上传,优先使用自定义域名
This commit is contained in:
parent
478db1bd39
commit
5804957149
@ -1,5 +1,7 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client;
|
package cn.iocoder.yudao.framework.file.core.client;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.file.core.client.s3.FilePresignedUrlBO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件客户端
|
* 文件客户端
|
||||||
*
|
*
|
||||||
@ -46,7 +48,7 @@ public interface FileClient {
|
|||||||
* @param fileName 文件名称
|
* @param fileName 文件名称
|
||||||
* @return 文件预签名地址
|
* @return 文件预签名地址
|
||||||
*/
|
*/
|
||||||
default String getPresignedObjectUrl(String fileName) throws Exception {
|
default FilePresignedUrlBO getPresignedObjectUrl(String fileName) throws Exception {
|
||||||
throw new UnsupportedOperationException("不支持的操作");
|
throw new UnsupportedOperationException("不支持的操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.yudao.framework.file.core.client.s3;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件预签名地址 BO
|
||||||
|
*
|
||||||
|
* @author owen
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class FilePresignedUrlBO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传 URL(用于上传)
|
||||||
|
*/
|
||||||
|
private String uploadUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件 URL(用于读取、下载等)
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
}
|
@ -120,8 +120,8 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPresignedObjectUrl(String fileName) throws Exception {
|
public FilePresignedUrlBO getPresignedObjectUrl(String fileName) throws Exception {
|
||||||
return client.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
String uploadUrl = client.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||||
.method(Method.PUT)
|
.method(Method.PUT)
|
||||||
.bucket(config.getBucket())
|
.bucket(config.getBucket())
|
||||||
.object(fileName)
|
.object(fileName)
|
||||||
@ -132,5 +132,6 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
|||||||
.expiry(10, TimeUnit.MINUTES)
|
.expiry(10, TimeUnit.MINUTES)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
return new FilePresignedUrlBO(uploadUrl, config.getDomain() + "/" + fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ public class FilePresignedUrlRespVO {
|
|||||||
@Schema(description = "配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11")
|
@Schema(description = "配置编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11")
|
||||||
private Long configId;
|
private Long configId;
|
||||||
|
|
||||||
|
@Schema(description = "文件上传 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/yudao.jpg")
|
||||||
|
private String uploadUrl;
|
||||||
|
|
||||||
@Schema(description = "文件 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/yudao.jpg")
|
@Schema(description = "文件 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/yudao.jpg")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClient;
|
import cn.iocoder.yudao.framework.file.core.client.FileClient;
|
||||||
|
import cn.iocoder.yudao.framework.file.core.client.s3.FilePresignedUrlBO;
|
||||||
import cn.iocoder.yudao.framework.file.core.utils.FileTypeUtils;
|
import cn.iocoder.yudao.framework.file.core.utils.FileTypeUtils;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||||
@ -109,8 +110,8 @@ public class FileServiceImpl implements FileService {
|
|||||||
@Override
|
@Override
|
||||||
public FilePresignedUrlRespVO getFilePresignedUrl(String fileName) throws Exception {
|
public FilePresignedUrlRespVO getFilePresignedUrl(String fileName) throws Exception {
|
||||||
FileClient fileClient = fileConfigService.getMasterFileClient();
|
FileClient fileClient = fileConfigService.getMasterFileClient();
|
||||||
String url = fileClient.getPresignedObjectUrl(fileName);
|
FilePresignedUrlBO bo = fileClient.getPresignedObjectUrl(fileName);
|
||||||
return new FilePresignedUrlRespVO(fileClient.getId(), url);
|
return BeanUtils.toBean(bo, FilePresignedUrlRespVO.class, f -> f.setConfigId(fileClient.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user