How to delete file from S3 using Spring cloud AWS?

元气小坏坏 提交于 2019-12-10 18:55:52

问题


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 ResourceLoaders that return Resources 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!