mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	📖 CRM:code review 前端直接上传
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
package cn.iocoder.yudao.framework.file.core.client;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.file.core.client.s3.FilePresignedUrlBO;
 | 
			
		||||
import cn.iocoder.yudao.framework.file.core.client.s3.FilePresignedUrlRespDTO;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 文件客户端
 | 
			
		||||
@@ -45,10 +45,10 @@ public interface FileClient {
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得文件预签名地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param fileName 文件名称
 | 
			
		||||
     * @param path 相对路径
 | 
			
		||||
     * @return 文件预签名地址
 | 
			
		||||
     */
 | 
			
		||||
    default FilePresignedUrlBO getPresignedObjectUrl(String fileName) throws Exception {
 | 
			
		||||
    default FilePresignedUrlRespDTO getPresignedObjectUrl(String path) throws Exception {
 | 
			
		||||
        throw new UnsupportedOperationException("不支持的操作");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,17 +5,19 @@ import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 文件预签名地址 BO
 | 
			
		||||
 * 文件预签名地址 Response DTO
 | 
			
		||||
 *
 | 
			
		||||
 * @author owen
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@Data
 | 
			
		||||
public class FilePresignedUrlBO {
 | 
			
		||||
public class FilePresignedUrlRespDTO {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 文件上传 URL(用于上传)
 | 
			
		||||
     *
 | 
			
		||||
     * 例如说:
 | 
			
		||||
     */
 | 
			
		||||
    private String uploadUrl;
 | 
			
		||||
 | 
			
		||||
@@ -120,18 +120,15 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public FilePresignedUrlBO getPresignedObjectUrl(String fileName) throws Exception {
 | 
			
		||||
    public FilePresignedUrlRespDTO getPresignedObjectUrl(String path) 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)
 | 
			
		||||
                .object(path)
 | 
			
		||||
                .expiry(10, TimeUnit.MINUTES) // 过期时间(秒数)取值范围:1 秒 ~ 7 天
 | 
			
		||||
                .build()
 | 
			
		||||
        );
 | 
			
		||||
        return new FilePresignedUrlBO(uploadUrl, config.getDomain() + "/" + fileName);
 | 
			
		||||
        return new FilePresignedUrlRespDTO(uploadUrl, config.getDomain() + "/" + path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user