How to load s3 object directly into memory in java

Is it possible to load S3object into Java directly into memory and delete it when I finished the task?

+8
amazon-s3 task
source share
1 answer

Use the AWS SDK for Java:

http://aws.amazon.com/sdkforjava/

And Apache Commons IO:

http://commons.apache.org/io/

Then it looks like this:

 AmazonS3 s3 = new AmazonS3Client(credentials); // anonymous credentials are possible if this isn't your bucket S3Object object = s3.getObject("bucket", "key"); byte[] byteArray = IOUtils.toByteArray(object.getObjectContent()); 

Not sure what you mean by β€œdelete”, but IOUtils will close the input stream of the object when it converts it to an array of bytes. If you want to remove an object from s3, this is simple:

 s3.deleteObject("bucket", "key"); 
+16
source share

All Articles