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
  • Field Details

    • FILENAME_METADATA_KEY

      public static final String FILENAME_METADATA_KEY
      S3 对象元数据中存储文件名的键。
      See Also:
  • 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

      public FileProviderEnum provider()
      Description copied from interface: IStorageService
      申明附件的存储类型
      Specified by:
      provider in interface IStorageService
      Returns:
      FileProviderEnum 存储类型枚举
    • getUploadInfo

      public UploadInfo getUploadInfo(Attachment attachment)
      获取文件上传信息。 如果文件大小超过分段上传阈值,则会检查或创建分段上传 ID。
      Specified by:
      getUploadInfo in interface IStorageService
      Parameters:
      attachment - 附件信息。
      Returns:
      文件上传信息。
    • getUploadAddress

      public UploadEndpoint getUploadAddress(Attachment attachment)
      创建预签名的 S3 URL,返回给前端。 用于单文件上传。
      Specified by:
      getUploadAddress in interface IStorageService
      Parameters:
      attachment - 附件信息。
      Returns:
      包含预签名 URL 的上传访问点。
    • getUploadAddress

      public UploadEndpoint getUploadAddress(Attachment attachment, int partNumber)
      Description copied from interface: IStorageService

      获取附件分段上传地址

      为给定附件的特定分段生成上传地址。 此方法适用于需要分段上传大文件的情况。

      Specified by:
      getUploadAddress in interface IStorageService
      Parameters:
      attachment - Attachment 附件对象,包含文件相关信息
      partNumber - 文件分段的序号
      Returns:
      UploadEndpoint 分段上传地址对象
    • getUploadAddress

      public UploadEndpoint getUploadAddress(Attachment attachment, Integer partNumber, String crc)
      创建预签名的 S3 URL,返回给前端。 用于分段上传的特定分段,并包含 CRC 校验码。
      Parameters:
      attachment - 附件信息。
      partNumber - 分段编号。
      crc - CRC 校验码。
      Returns:
      包含预签名 URL 的上传访问点。
    • getDownloadEndpoint

      public DownloadEndpoint getDownloadEndpoint(Attachment attachment)
      Description copied from interface: IStorageService

      获取附件下载地址

      为给定的附件生成一个用于下载文件的地址。

      Specified by:
      getDownloadEndpoint in interface IStorageService
      Parameters:
      attachment - Attachment 附件信息对象
      Returns:
      DownloadEndpoint 下载地址对象
    • upload

      public void upload(Attachment attachment, byte[] fileContent)
      Description copied from interface: IStorageService

      上传文件

      将文件内容上传到存储服务。

      Specified by:
      upload in interface IStorageService
      Parameters:
      attachment - Attachment 附件对象,包含文件相关信息
      fileContent - 文件内容的字节数组
    • download

      public byte[] download(Attachment attachment)
      Description copied from interface: IStorageService

      下载文件

      从存储服务下载指定附件的内容。

      Specified by:
      download in interface IStorageService
      Parameters:
      attachment - Attachment 附件对象,包含文件相关信息
      Returns:
      文件内容的字节数组