Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3.headObject - where is ContentLength? #631

Closed
dirkraft opened this issue Jun 18, 2015 · 6 comments
Closed

s3.headObject - where is ContentLength? #631

dirkraft opened this issue Jun 18, 2015 · 6 comments
Labels
guidance Question that needs advice or information.

Comments

@dirkraft
Copy link

I'm trying to get the size of a file in S3 (from the browser) without actually downloading the entire file. It seems like Content-Length or response.ContentLength just isn't there. Am I misunderstanding how this works?

Here's a fiddle that gets a public-accessible file from S3 to show this. http://jsfiddle.net/dirkraft/9xbpoL8v/3/

Some environment details

Google Chrome   43.0.2357.124 (Official Build) (64-bit)
OS X Yosemite 10.10.3
aws-sdk-js 2.1.35
@dirkraft
Copy link
Author

Added some environment details to the description

@lsegal
Copy link
Contributor

lsegal commented Jun 19, 2015

@dirkraft if you're running this from the browser you have to ensure that you've exposed the headers you want in your CORS configuration (see the ExposeHeader field). The SDK will not be able to access any response headers that are not exposed in this way, as a CORS security restriction in your browser.

@dirkraft
Copy link
Author

Thanks for the quick response. This is the CORS of s3://bits.dirkraft.com as of now (just added the ExposeHeader element)

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <MaxAgeSeconds>300</MaxAgeSeconds>
        <ExposeHeader>Content-Length</ExposeHeader>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

curl seems(?) to see a header named Content-Length

$ curl -XHEAD -v https://s3.amazonaws.com/bits.dirkraft.com/favicon.ico
* Hostname was NOT found in DNS cache
*   Trying 54.231.244.4...
* Connected to s3.amazonaws.com (54.231.244.4) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate: s3.amazonaws.com
* Server certificate: VeriSign Class 3 Secure Server CA - G3
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> HEAD /bits.dirkraft.com/favicon.ico HTTP/1.1
> User-Agent: curl/7.37.1
> Host: s3.amazonaws.com
> Accept: */*
>
< HTTP/1.1 200 OK
< x-amz-id-2: WZUhqzQOsfOI0HZ2QUvcg7S4kxBthaAZH6CAdvOL3HIzEsz6VXVvq9b8pHlXIc9g
< x-amz-request-id: 253D39519E8216DC
< Date: Fri, 19 Jun 2015 00:09:14 GMT
< Last-Modified: Sun, 23 Nov 2014 20:43:42 GMT
< ETag: "811119f4bb4ac6e00593c2b6eb92acc6"
< Accept-Ranges: bytes
< Content-Type: image/x-icon
< Content-Length: 318
* Server AmazonS3 is not blacklisted
< Server: AmazonS3
<
* transfer closed with 318 bytes remaining to read
* Closing connection 0
curl: (18) transfer closed with 318 bytes remaining to read

so does Chrome dev tools
screen shot 2015-06-19 at 12 12 57 am

Any more pointers?

@lsegal
Copy link
Contributor

lsegal commented Jun 19, 2015

It's showing up in the Fiddle now for me.

@dirkraft
Copy link
Author

Ah it does now for me too. Fantastic. Thanks very much and keep up the great stuff

@lock
Copy link

lock bot commented Sep 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

3 participants