Skip to content

Commit b5a8532

Browse files
committed
GetObjectRequest should support final bytes as a Range header value
Fixes aws#1551
1 parent 9b656cf commit b5a8532

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/AmazonS3Client.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,11 @@ public S3Object getObject(GetObjectRequest getObjectRequest)
14611461
// Range
14621462
long[] range = getObjectRequest.getRange();
14631463
if (range != null) {
1464-
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]) + "-" + Long.toString(range[1]));
1464+
if (range[0] < 0) {
1465+
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]));
1466+
} else {
1467+
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]) + "-" + Long.toString(range[1]));
1468+
}
14651469
}
14661470

14671471
populateRequesterPaysHeader(request, getObjectRequest.isRequesterPays());

aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/model/GetObjectRequest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ public void setRange(long start, long end) {
474474
* <p>
475475
* The first byte in an object has
476476
* position 0; as an example, the object is of 10 bytes in length, the last
477-
* 4 bytes can be downloaded by specifying the start range as 6.
477+
* 4 bytes can be downloaded by specifying the start range as 6. Positions
478+
* may also be specified as a negative number counting from the end of the
479+
* object. Therefore, start = -4 will get the last four bytes of the
480+
* object regardless of its length.
478481
* </p>
479482
* <p>
480483
* If no byte range is specified, this request downloads the entire
@@ -534,7 +537,10 @@ public GetObjectRequest withRange(long start, long end) {
534537
* <p>
535538
* The first byte in an object has
536539
* position 0; as an example, the object is of 10 bytes in length, the last
537-
* 4 bytes can be downloaded by specifying the start range as 6.
540+
* 4 bytes can be downloaded by specifying the start range as 6. Positions
541+
* may also be specified as a negative number counting from the end of the
542+
* object. Therefore, start = -4 will get the last four bytes of the
543+
* object regardless of its length.
538544
* </p>
539545
* <p>
540546
* If no byte range is specified, this request downloads the entire

0 commit comments

Comments
 (0)