javaamazon-web-servicesspring-bootamazon-s3aws-sdk-java

Copy files from S3 bucket to any destination (like sharepoint) other than S3 bucket


Under AWS JAVA SDK, I can see AmazonS3.java, TransferManager.java for copying/transferring files between two S3 buckets. I want to know what can be used when the destination is NOT a S3 bucket. I have a requirement where I need to transfer from S3 bucket to SharePoint but under AWS Java SDK I can't find any utility to copy/move files from S3 bucket to any destination other than another bucket. Please help.


Solution

  • The general solution is to use S3Client.getObject(objectRequest) which is a ResponseInputStream<GetObjectResponse>. This AWS specific object is subclass of the standard java.io.InputStream.

    So all you need to do is read that stream...

    1. indirectly into a File, and then pass the file handle to your Sharepoint client
    2. indirectly into an in-memory byte store (if there's enough RAM), and then pass the byte[] to your Sharepoint client
    3. or open up an output stream on your Sharepoint client and stream from S3 to Sharepoint directly.

    The actual byte moving could be assisted with a tool such as Apache Commons IO: IOUtils