Sandeep
Sandeep

Reputation: 243

How to stream S3 object directly from Java web server to browser

What I have tried so far is

S3Object object = s3Object.getObject(new getObjectRequest(bucketName,FileName));
InputStreamResource inputStreamResource = object.getObjectContent();
// Setting Headers.
return new ResponseEntity(inputStreamResource,headers, HttpStatus.OK);

But this code is not streaming date to browser. I has first downloaded to server and then sent back to browser but requirement is to directly stream to browser without downloading at server.

Any pseudocode or link will help.

Thanks

Upvotes: 1

Views: 768

Answers (1)

Instead of calling getObject(), create a signed GET request and send a 302 redirect to the client. The browser will then retrieve the object directly from Amazon. In case you aren't already using it, the jets3t library makes dealing with S3 signatures much simpler.

Upvotes: 4

Related Questions