问题
I could not find any API or documentation in Spring AWS Cloud to delete an object from S3 bucket. Can someone please let me know how to do it?
The documentation just talks about reading the content using ResourceLoader
.
Only option right now I see is to explicitly inject AmazonS3
and call deleteObject
.
回答1:
Spring's Resource API does not support the full lifecycle of operations. The two main interfaces are Resource
and WritableResource
. There is no API for deletion.
As an alternative you could use Spring Content for S3 instead. Spring Content Stores are all generic ResourceLoader
s that return Resource
s that DO support deletion. That, by the way, works exactly as you are suggesting.
Take a look at the reference guide. The base Store
interface is the one that should be a straight drop-in for the one from Spring Cloud AWS.
Simply cast the return from getResource
to DeletableResource
and call it's delete
to delete the object in S3.
Let me know if this is not clear and I can update with more details.
来源:https://stackoverflow.com/questions/51304075/how-to-delete-file-from-s3-using-spring-cloud-aws