如何使用Spring Cloud AWS从S3删除文件? [英] How to delete file from S3 using Spring cloud AWS?

查看:200
本文介绍了如何使用Spring Cloud AWS从S3删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Spring AWS Cloud中找到任何API或文档来从S3存储桶中删除对象.有人可以让我知道怎么做吗?

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?

文档只是谈论阅读内容使用ResourceLoader.

The documentation just talks about reading the content using ResourceLoader.

我现在看到的唯一选项是显式注入AmazonS3并调用deleteObject.

Only option right now I see is to explicitly inject AmazonS3 and call deleteObject.

推荐答案

Spring的Resource API不支持操作的整个生命周期.两个主要接口是ResourceWritableResource.没有要删除的API.

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.

作为替代方案,您可以将 Spring Content 用于

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.

请参阅参考指南.基本的Store接口应该是Spring Cloud AWS中的直接接口.

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.

只需将返回值从getResource强制转换为DeletableResource,并称其为delete即可删除S3中的对象.

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.

这篇关于如何使用Spring Cloud AWS从S3删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆