Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm familiar with the Range HTTP header; however, the interface I'm using to query S3 (an img element's .src property) doesn't allow me to specify HTTP headers.

Is there a way for me to specify my desired range via a parameter in the query string?

It doesn't seem like there is, but I'm just holding out a shred of hope before I roll my own solution with ajax requests.

Sorry to destroy your last shred of hope, but no, there's not a documented way to do this... but also, given that rfc-7233 indicates that Range: support is optional in servers and proxies, and that the concept of a "partial" img is not necessarily something browsers might universally understand as a sane concept... what are you trying to accomplish with only a subset of an image's data? Michael - sqlbot Nov 17, 2014 at 10:52

Amazon S3 supports Range GET requests, as do some HTTP servers, for example, Apache and IIS.

How CloudFront Processes Partial Requests for an Object (Range GETs)

I tried to get my S3 object via cURL:

curl -r 0-1024 https://s3.amazonaws.com/mybucket/myobject -o part1
curl -r 1025-  https://s3.amazonaws.com/mybucket/myobject -o part2
cat part1 part2 > myobject

and AWS SDK for JavaScript:

var s3 = new AWS.S3();
var file = require('fs').createWriteStream('part1');
var params = {
    Bucket: 'mybucket',
    Key: 'myobject',
    Range: 'bytes=0-1024'
s3.getObject(params).createReadStream().pipe(file);

These two methods work fine for me.

AWS SDK for JavaScript API Reference (getObject)

in the above example will it download 1024 bytes or 1023? Is the end range value exclusive or inclusive? – Shwetabh Shekhar Apr 16, 2018 at 5:57 @ShwetabhShekhar appears to be inclusive; in fact 0-1024 gives 1025 bytes, not 1024 or 1023 – Janaka Bandara Sep 19, 2018 at 2:54

Below is the Java Code with AWS V2 SDK

format the range as below

var range = String.format("bytes=%d-%d", start, end);

and pass it in below api with GetObjectRequest builder

 ResponseBytes<GetObjectResponse> currentS3Obj = client.getObjectAsBytes(GetObjectRequest.builder().bucket(bucket).key(key).range(range).build());
return currentS3Obj.asInputStream();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.