amazon-web-services - S3 警告 : "No content length specified for stream data"

标签 amazon-web-services amazon-s3 aws-sdk

我突然开始看到这条警告消息被记录下来,即使底层 aws 库的使用或基础上没有任何变化。我一直在使用 aws-java-sdk 版本 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 对象上设置内容长度,但这就是之前的情况,并且没有生成警告。

任何人都知道为什么会突然开始出现此警告消息?

谢谢!

最佳答案

我知道这已经有一段时间了,但我今天不得不处理这个问题,并在文档中找到了这个解释。

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/ObjectMetadata.html#setContentLength-long-

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.

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



在我的情况下,我必须缓冲流,所以我使用了这样的东西:

https://books.google.com/books?id=cXggAQAAQBAJ&pg=PA377&lpg=PA377&dq=content+length+of+bytebuffer+java&source=bl&ots=AQSUOUwoI6&sig=tdok7YyipU7YUI6p1Bu_2X9HT6s&hl=en&sa=X&ved=0ahUKEwigi_DhiJPVAhVk8IMKHVWLBmAQ6AEIiQEwCA#v=onepage&q=content%20length%20of%20bytebuffer%20java&f=false
ByteBuffer buffer = new ByteBuffer(...)
...
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(buffer.limit());

关于amazon-web-services - S3 警告 : "No content length specified for stream data",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32967067/

相关文章:

amazon-web-services - 我应该如何将 Amazon RDS 集成到 Flutter 中?任何本地 Dart 支持包?

javascript - 为什么使用 Step 函数 (AWS) 而不是 setTimeout(Javascript) 来实现调度程序功能

amazon-web-services - `aws s3 cp` 与 `aws s3 sync` 行为和成本

javascript - 使用 Javascript 创建带有 JSON 信息的网站链接?

ios - 没有这样的文件位置 - 将图像从 Swift 上传到 S3

node.js - aws-sdk 导致 Nodejs 程序崩溃

aws-sdk - aws sdk中是否有节点的s3移动功能

amazon-web-services - 如何使用AWS深度学习docker容器

amazon-web-services - AWS 相当于 Firebase 实时数据库的是什么?

ubuntu - 将大数据从 Droplet 同步到 Digital Ocean Space (S3)