S3Template

class S3Template(s3Properties: S3Properties) : InitializingBean

S3 操作模板

封装常用的存储桶、对象和预签名 URL 操作

Constructors

Link copied to clipboard
constructor(s3Properties: S3Properties)

Functions

Link copied to clipboard
open override fun afterPropertiesSet()

读取配置并创建 S3 客户端与预签名器

Link copied to clipboard
fun createBucket(bucketName: String)

创建存储桶

Link copied to clipboard
fun getAllBuckets(): List<Bucket>

获取所有存储桶

Link copied to clipboard
fun getAllObjectsByPrefix(bucketName: String, prefix: String): List<S3Object>

按前缀列出对象

Link copied to clipboard
fun getBucket(bucketName: String): Bucket?

按名称获取存储桶

Link copied to clipboard
fun getObject(bucketName: String, objectName: String): InputStream

读取对象内容

Link copied to clipboard
fun getObjectInfo(bucketName: String, objectName: String): HeadObjectResponse

获取对象元数据

Link copied to clipboard
fun getObjectURL(bucketName: String, objectName: String): String

拼接对象访问地址

fun getObjectURL(bucketName: String, objectName: String, expires: Duration): String
fun getObjectURL(bucketName: String, objectName: String, minutes: Int): String

生成对象下载预签名 URL

fun getObjectURL(bucketName: String, objectName: String, expires: Duration, httpMethod: String): String
fun getObjectURL(bucketName: String, objectName: String, minutes: Int, httpMethod: String): String

按 HTTP 方法生成对象预签名 URL

Link copied to clipboard
fun getPutObjectURL(bucketName: String, objectName: String, expires: Duration): String
fun getPutObjectURL(bucketName: String, objectName: String, minutes: Int): String

生成对象上传预签名 URL

Link copied to clipboard
fun headBucket(bucketName: String): Boolean

检查存储桶是否存在

Link copied to clipboard
fun putObject(bucketName: String, objectName: String, stream: InputStream)

上传对象

fun putObject(bucketName: String, objectName: String, contextType: String, stream: InputStream)

上传指定内容类型的对象

fun putObject(bucketName: String, objectName: String, stream: InputStream, size: Long, contextType: String): PutObjectResponse

上传指定长度的对象

Link copied to clipboard
fun removeBucket(bucketName: String)

删除存储桶

Link copied to clipboard
fun removeObject(bucketName: String, objectName: String)

删除对象