mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-23 23:45:08 +08:00
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.framework.file.core.client;
|
||||
|
||||
import cn.iocoder.yudao.framework.file.core.client.s3.FilePresignedUrlBO;
|
||||
|
||||
/**
|
||||
* 文件客户端
|
||||
*
|
||||
@ -18,11 +20,11 @@ public interface FileClient {
|
||||
* 上传文件
|
||||
*
|
||||
* @param content 文件流
|
||||
* @param path 相对路径
|
||||
* @param path 相对路径
|
||||
* @return 完整路径,即 HTTP 访问地址
|
||||
* @throws Exception 上传文件时,抛出 Exception 异常
|
||||
*/
|
||||
String upload(byte[] content, String path, String type) throws Exception;
|
||||
String upload(byte[] content, String path, String type) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
@ -40,4 +42,14 @@ public interface FileClient {
|
||||
*/
|
||||
byte[] getContent(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 获得文件预签名地址
|
||||
*
|
||||
* @param fileName 文件名称
|
||||
* @return 文件预签名地址
|
||||
*/
|
||||
default FilePresignedUrlBO getPresignedObjectUrl(String fileName) throws Exception {
|
||||
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;
|
||||
|
||||
}
|
@ -5,8 +5,10 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
|
||||
import io.minio.*;
|
||||
import io.minio.http.Method;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig.ENDPOINT_ALIYUN;
|
||||
import static cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig.ENDPOINT_TENCENT;
|
||||
@ -117,4 +119,19 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||
return IoUtil.readBytes(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePresignedUrlBO getPresignedObjectUrl(String fileName) throws Exception {
|
||||
String uploadUrl = client.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.PUT)
|
||||
.bucket(config.getBucket())
|
||||
.object(fileName)
|
||||
/**
|
||||
* 过期时间(秒数)取值范围:1秒 ~ 7天
|
||||
* {@link GetPresignedObjectUrlArgs.Builder#validateExpiry(int)}
|
||||
*/
|
||||
.expiry(10, TimeUnit.MINUTES)
|
||||
.build()
|
||||
);
|
||||
return new FilePresignedUrlBO(uploadUrl, config.getDomain() + "/" + fileName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user