Class S3Service
java.lang.Object
io.github.xezzon.zeroweb.storage.s3.S3Service
- All Implemented Interfaces:
IStorageService
@Service
@ConditionalOnBean(ZerowebS3Config.class)
public class S3Service
extends Object
implements IStorageService
S3 对象存储服务实现。
如果没有配置 S3,则不会注册 Bean。
- Author:
- xezzon
-
Nested Class Summary
Nested classes/interfaces inherited from interface IStorageService
IStorageService.Factory -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionS3Service(ZerowebS3Config zerowebS3Config, software.amazon.awssdk.services.s3.presigner.S3Presigner s3Presigner, software.amazon.awssdk.services.s3.S3Client s3Client, S3UploadIdRepository s3UploadIdRepository) 注入依赖 -
Method Summary
Modifier and TypeMethodDescriptionbyte[]download(Attachment attachment) 下载文件getDownloadEndpoint(Attachment attachment) 获取附件下载地址getUploadAddress(Attachment attachment) 创建预签名的 S3 URL,返回给前端。getUploadAddress(Attachment attachment, int partNumber) 获取附件分段上传地址getUploadAddress(Attachment attachment, Integer partNumber, String crc) 创建预签名的 S3 URL,返回给前端。getUploadInfo(Attachment attachment) 获取文件上传信息。provider()申明附件的存储类型voidupload(Attachment attachment, byte[] fileContent) 上传文件
-
Field Details
-
FILENAME_METADATA_KEY
-
-
Constructor Details
-
S3Service
public S3Service(ZerowebS3Config zerowebS3Config, software.amazon.awssdk.services.s3.presigner.S3Presigner s3Presigner, software.amazon.awssdk.services.s3.S3Client s3Client, S3UploadIdRepository s3UploadIdRepository) 注入依赖- Parameters:
zerowebS3Config- S3 配置。s3Presigner- S3 预签名器。s3Client- S3 客户端。s3UploadIdRepository- S3 上传 ID 仓库。
-
-
Method Details
-
provider
Description copied from interface:IStorageService申明附件的存储类型- Specified by:
providerin interfaceIStorageService- Returns:
FileProviderEnum存储类型枚举
-
getUploadInfo
获取文件上传信息。 如果文件大小超过分段上传阈值,则会检查或创建分段上传 ID。- Specified by:
getUploadInfoin interfaceIStorageService- Parameters:
attachment- 附件信息。- Returns:
- 文件上传信息。
-
getUploadAddress
创建预签名的 S3 URL,返回给前端。 用于单文件上传。- Specified by:
getUploadAddressin interfaceIStorageService- Parameters:
attachment- 附件信息。- Returns:
- 包含预签名 URL 的上传访问点。
-
getUploadAddress
Description copied from interface:IStorageService获取附件分段上传地址
为给定附件的特定分段生成上传地址。 此方法适用于需要分段上传大文件的情况。
- Specified by:
getUploadAddressin interfaceIStorageService- Parameters:
attachment-Attachment附件对象,包含文件相关信息partNumber- 文件分段的序号- Returns:
UploadEndpoint分段上传地址对象
-
getUploadAddress
创建预签名的 S3 URL,返回给前端。 用于分段上传的特定分段,并包含 CRC 校验码。- Parameters:
attachment- 附件信息。partNumber- 分段编号。crc- CRC 校验码。- Returns:
- 包含预签名 URL 的上传访问点。
-
getDownloadEndpoint
Description copied from interface:IStorageService获取附件下载地址
为给定的附件生成一个用于下载文件的地址。
- Specified by:
getDownloadEndpointin interfaceIStorageService- Parameters:
attachment-Attachment附件信息对象- Returns:
DownloadEndpoint下载地址对象
-
upload
Description copied from interface:IStorageService上传文件
将文件内容上传到存储服务。
- Specified by:
uploadin interfaceIStorageService- Parameters:
attachment-Attachment附件对象,包含文件相关信息fileContent- 文件内容的字节数组
-
download
Description copied from interface:IStorageService下载文件
从存储服务下载指定附件的内容。
- Specified by:
downloadin interfaceIStorageService- Parameters:
attachment-Attachment附件对象,包含文件相关信息- Returns:
- 文件内容的字节数组
-