mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-13 18:45:06 +08:00
基础设施:增加前端直连上传文件到S3服务的功能
This commit is contained in:
@ -18,11 +18,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 +40,14 @@ public interface FileClient {
|
||||
*/
|
||||
byte[] getContent(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 获得文件预签名地址
|
||||
*
|
||||
* @param fileName 文件名称
|
||||
* @return 文件预签名地址
|
||||
*/
|
||||
default String getPresignedObjectUrl(String fileName) throws Exception {
|
||||
throw new UnsupportedOperationException("不支持的操作");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,18 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||
return IoUtil.readBytes(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresignedObjectUrl(String fileName) throws Exception {
|
||||
return client.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.PUT)
|
||||
.bucket(config.getBucket())
|
||||
.object(fileName)
|
||||
/**
|
||||
* 过期时间(秒数)取值范围:1秒 ~ 7天
|
||||
* {@link GetPresignedObjectUrlArgs.Builder#validateExpiry(int)}
|
||||
*/
|
||||
.expiry(10, TimeUnit.MINUTES)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user