Choose your storage product

Polycloud

Object Storage

10 GB FREE

Device Backup

WD My Cloud Home

 

Choose your storage product

Polycloud

Object Storage

10 GB FREE

Device Backup

WD My Cloud Home

 

AWS SDK for Java

Installation:

The AWS SDK for Java requires Java 8.0 or later. You can install it 1 of 2 ways:

1) http://www.oracle.com/technetwork/java/javase/downloads/
2) https://openjdk.java.net/install/index.html

The recommended way to use the AWS SDK for Java in your project is via Maven. Installation instructions for Maven can be found at http://maven.apache.org/

Create a Maven project

$ mvn -B archetype:generate \
-DarchetypeGroupId=software.amazon.awssdk \
-DarchetypeArtifactId=archetype-lambda -Dservice=s3 -Dregion=US_EAST_1 \
-DgroupId=com.example.myapp \
-DartifactId=myapp

Edit `myapp/src/main/java/com/example/myapp/App.java` to have the following contents (substituting `mybucket` with your information):

package com.example.myapp;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.model.S3Object;
import java.util.List;
import java.util.ListIterator;
import java.net.URI;

public class App {
    public static void main(String[] args) {
        String bucketName = "mybucket";
        Region region = Region.US_EAST_1;
        URI endpoint = URI.create("https://polycloud.crowdapis.com");
        S3Client s3 = S3Client.builder().region(region).endpointOverride(endpoint).build();
        listBucketObjects(s3, bucketName);
    }

    public static void listBucketObjects(S3Client s3, String bucketName ) {
       try {
            ListObjectsRequest listObjects = ListObjectsRequest.builder().bucket(bucketName).build();

            ListObjectsResponse res = s3.listObjects(listObjects);
            List<S3Object> objects = res.contents();

            for (ListIterator iterVals = objects.listIterator(); iterVals.hasNext(); ) {
                S3Object myValue = (S3Object) iterVals.next();
                System.out.print(myValue.key());
                }
        } catch (S3Exception e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
    }
}

Compile and run the example:

$ cd myapp
$ mvn package
$ cd target
$ AWS_ACCESS_KEY_ID=<your access key> AWS_SECRET_ACCESS_KEY=<your secret> java -c