Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 warning: "No content length specified for stream data"

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.

This is howthe file is uploaded:

client.putObject(bucketName, key, new ByteArrayInputStream(data), new 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?

Thanks!

like image 948
vaudeville Avatar asked Oct 06 '15 09:10

vaudeville


1 Answers

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

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

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());
like image 91
PaulSCoder Avatar answered Sep 21 '22 20:09

PaulSCoder