We have some Java services that upload files to an S3 compatible storage and generate Presigned URLs. Other Java services receive such URLs and work on the files. We need the content length of this file, without loading the whole object from the body. Is this possible? And if yes, how?
We upload via
com.amazonaws.services.s3.AmazonS3.putObject()
and create URLs with
com.amazonaws.services.s3.AmazonS3.generatePresignedUrl()
When I check the Http Headers of a file using my S3 Browser, I can see the correct Content-Length entry.
But in our services we use
OkHttpClient.newCall(
new Builder().get()
.url(url).build()
).execute();
And in those Response objects there is no Content-Length.
If the response is streamed (HTTP/1.1 chunked) or compressed then it won't have a content length to read from. You can probably use a HEAD request to get the headers without the body and check first.