Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AWS S3 bucket中使用spring boot实现文件上传的最佳方式是什么?_Spring_Amazon S3_Spring Boot Test - Fatal编程技术网

在AWS S3 bucket中使用spring boot实现文件上传的最佳方式是什么?

在AWS S3 bucket中使用spring boot实现文件上传的最佳方式是什么?,spring,amazon-s3,spring-boot-test,Spring,Amazon S3,Spring Boot Test,在JavaSpringBoot应用程序(使用WebStarter的Web服务)上工作时,我需要将图像存储在S3存储桶中,有人能建议我如何实现吗 在EC2实例中托管应用程序您可以将spring cloud aws与支持s3的ResourceLoader一起使用: <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aws-context="http://www.springframework.org/sche

在JavaSpringBoot应用程序(使用WebStarter的Web服务)上工作时,我需要将图像存储在S3存储桶中,有人能建议我如何实现吗


在EC2实例中托管应用程序

您可以将spring cloud aws与支持s3的ResourceLoader一起使用:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context"
   xsi:schemaLocation="http://www.springframework.org/schema/cloud/aws/context http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd">
    <aws-context:context-credentials>
       <!-- ... -->
     </aws-context:context-credentials>
    <aws-context:context-resource-loader/>
</beans>
您可以在此处找到文档: 我终于找到了解决办法 请参阅下面的博客以实现Spring boot AWS s3上载映像和删除映像


链接

:D谢谢@erwinbolwidt请注意,这不适用于S3服务器端加密(SSE),因为无法修改上传的元数据。因此,该解决方案具有限制性。
public class SimpleResourceLoadingBean {

@Autowired
private ResourceLoader resourceLoader;

public void writeResource() throws IOException {
        Resource resource = this.resourceLoader.getResource("s3://myBucket/rootFile.log");
        WritableResource writableResource = (WritableResource) resource;
        try (OutputStream outputStream = writableResource.getOutputStream()) {
            outputStream.write("test".getBytes());
        }
    }
}