如何为S3对象创建Java OutputStream并向其中写入值? [英] How to create a java OutputStream for an S3 object and write value to it?

查看:68
本文介绍了如何为S3对象创建Java OutputStream并向其中写入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AmazonS3类中的方法向S3文件添加内容的现有方法是

Existing ways of adding content to an S3 file using methods in AmazonS3 class are

  • 通过带InputStream的putObject
  • 创建包含内容的本地文件并将其上传到S3.

是否可以为现有的S3对象创建一个OutputStream,可以将列表中的值写入其中?我看到没有这样做的API.

Is there a way an OutputStream can be created for an existing S3 object to which values from a list can be written into? I see there are no APIs for doing so.

推荐答案

可以创建一个包装AmazonS3客户端的S3OutputStream.有关实现,请参见以下要点: https://gist.github.com/blagerweij/ad1dbb7ee2fff8bcffd372815ad310eb 它会自动检测大文件,并在需要时使用多部分传输.它使用字节数组进行缓冲,该缓冲区的大小取决于您的用例.(默认为10MB)

It's possible to create an S3OutputStream which wraps the AmazonS3 client. See this gist for the implementation: https://gist.github.com/blagerweij/ad1dbb7ee2fff8bcffd372815ad310eb It automatically detects large files, and uses multi-part transfers when required. It uses a byte-array for buffering, the size of that buffer depends on your use case. (default is 10MB)

例如:

   final S3Client s3Client = AmazonS3ClientBuilder.defaultClient();
   final OutputStream out = new S3OutputStream(s3Client, "bucket", "path/file.ext");

这篇关于如何为S3对象创建Java OutputStream并向其中写入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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