How to get (first n bytes of) file from s3 url

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 02:24:22

If you use the AWS SDK for Java, you would just set the range on the GetObjectRequest. Here is a code example:

AmazonS3Client s3Client = new AmazonS3Client();
GetObjectRequest request = new GetObjectRequest("bucket-name", "foo/1/2/3/4/file.jpg");
request.withRange(0, numberOfBytesToGet);
S3Object s3Object = s3Client.getObject(request);
//s3Object.getObjectContent() has a stream to your object.

If you are struggling to do this in Ruby (which we were for ages) the correct syntax is:

s3_resource.bucket(bucket).object(key).get(range: "bytes=0-3").body.read
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!