S3 警告:“没有为流数据指定内容长度" [英] S3 warning: "No content length specified for stream data"

查看:31
本文介绍了S3 警告:“没有为流数据指定内容长度"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我突然开始看到此警告消息被记录,即使底层 aws 库的使用或基础上没有任何变化.我一直在使用 aws-java-sdk 版本 1.6.9.1

I suddenly started seeing this warning message being logged, even though there were no changes in the usage of or on the underlying aws libs. I've been using aws-java-sdk version 1.6.9.1

没有为流数据指定内容长度.流内容将缓冲在内存中,并可能导致内存不足错误.

No content length specified for stream data. Stream contents will be buffered in memory and could result in out of memory errors.

文件上传方式如下:

client.putObject(bucketName, key, new ByteArrayInputStream(data), new ObjectMetadata())

我怀疑我可能看到了这一点,因为我没有在 ObjectMetadata 对象上设置内容长度,但以前是这样,没有生成警告.

I suspect I may be seeing this because I'm not setting the content length on the ObjectMetadata object, but that's how it was before and no warning was being generated.

有人知道为什么会突然开始出现这条警告消息吗?

Anyone has any insight as to why this warning message would suddenly start appearing?

谢谢!

推荐答案

我知道这已经有一段时间了,但我今天不得不处理这个问题,并在 docs.

I know this has been a while but I just had to deal with this today and found this explanation in the docs.

上传文件时,AWS S3 Java 客户端将尝试确定如果尚未设置正确的内容类型.用户是负责确保上传时设置了合适的内容类型流.如果未提供内容类型且无法确定文件名,默认内容类型,应用程序/八位字节流",将被使用.

When uploading files, the AWS S3 Java client will attempt to determine the correct content type if one hasn't been set yet. Users are responsible for ensuring a suitable content type is set when uploading streams. If no content type is provided and cannot be determined by the filename, the default content type, "application/octet-stream", will be used.

有关 Content-Type 标头的更多信息,请参阅http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17

For more information on the Content-Type header, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17

就我而言,我不得不缓冲流,所以我使用了这样的东西(来自 参考).

In my case I had to buffer the stream so I used something like this (from this reference).

ByteBuffer buffer = new ByteBuffer(...)
...
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(buffer.limit());

这篇关于S3 警告:“没有为流数据指定内容长度"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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