英文:
AWS S3 deleteMarker() retrun null
问题
我正在使用适用于 Kotlin 的 AWS SDK 与 Spring。我设置了两个 AWS SDK 的依赖项。我创建了一个删除函数。但是它返回了错误的值。首先,我使用 deleteObject 删除文件。其次,我检查了是否已经使用 deleteMarker() 进行了删除。deleteMarker 函数的返回类型是布尔值。然后在执行 delete 函数之后,我检查了 AWS S3 以确认文件是否已删除。这一步是正确执行的。但是,它返回了空值。
implementation("software.amazon.awssdk:s3:2.14.0") // Amazon S3
implementation("software.amazon.awssdk:aws-sdk-java:2.14.0") // Amazon 所有服务
fun remove(path: String): Boolean {
val result = s3.deleteObject(
DeleteObjectRequest.builder().bucket(bucket.name()).key(path).build()
)
logger.info("在桶中删除:$path - ${result.deleteMarker()}")
return result.deleteMarker()
}
/* 错误消息和日志 */
/*
在桶中删除:27313e6a7307240ab190d805cc5ddd72fb24458f6b96b84616babdc85a691a30 - null
java.lang.IllegalStateException: result.deleteMarker() 不能为空
at com.hanmedia.server.service.AwsService.remove(AwsService.kt:59) ~[main/:na]
*/
英文:
I'm using the AWS SDK for Kotlin with Spring. I set dependencies two AWS SDKs. I made remove function. That ran wrong return value. Firstly, I remove file to use deleteObject. Secondly, It checked that is removed to use deleteMarker(). deleteMarker function return type is boolean. And then delete function ran after, I checked AWS S3 for checked removing file. It was run correctly. But, It returned null.
implementation("software.amazon.awssdk:s3:2.14.0") // Amazon S3
implementation("software.amazon.awssdk:aws-sdk-java:2.14.0") // Amazon All service
fun remove(path : String): Boolean {
val result = s3.deleteObject(
DeleteObjectRequest.builder().bucket(bucket.name()).key(path).build()
)
logger.info("remove in bucket : $path - ${result.deleteMarker()}")
return result.deleteMarker()
}
/* error message and log */
/*
remove in bucket : 27313e6a7307240ab190d805cc5ddd72fb24458f6b96b84616babdc85a691a30 - null
java.lang.IllegalStateException: result.deleteMarker() must not be null
at com.hanmedia.server.service.AwsService.remove(AwsService.kt:59) ~[main/:na]
*/
答案1
得分: 2
一个删除标记只会在您处理版本化存储桶时才会出现。看起来您有一个“普通”存储桶,在这种情况下没有删除标记,一个对象要么存在要么不存在。
英文:
A delete marker will only be present if you are dealing with versioned buckets. Seems like you have a "normal" bucket in which case there are no delete markers, an object is simply there or it isn't.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论