Search in sources :

Example 6 with AmazonS3ClientBuilder.defaultClient

use of com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient in project aws-doc-sdk-examples by awsdocs.

the class ImportSegment method uploadToS3.

private static void uploadToS3(File endpointsFile, String s3BucketName) {
    // Initializes Amazon S3 client.
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    // Checks whether the specified bucket exists. If not, attempts to create one.
    if (!s3.doesBucketExistV2(s3BucketName)) {
        try {
            s3.createBucket(s3BucketName);
            System.out.format("Created S3 bucket %s.\n", s3BucketName);
        } catch (AmazonS3Exception e) {
            System.err.println(e.getErrorMessage());
            System.exit(1);
        }
    }
    // Uploads the endpoints file to the bucket.
    String endpointsFileName = endpointsFile.getName();
    System.out.format("Uploading %s to S3 bucket %s . . .\n", endpointsFileName, s3BucketName);
    try {
        s3.putObject(s3BucketName, "imports/" + endpointsFileName, endpointsFile);
        System.out.println("Finished uploading to S3.");
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 7 with AmazonS3ClientBuilder.defaultClient

use of com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient in project aws-doc-sdk-examples by awsdocs.

the class DisplayFaces method main.

public static void main(String[] arg) throws Exception {
    // Change the value of bucket to the S3 bucket that contains your image file.
    // Change the value of photo to your image file name.
    String photo = "input.png";
    String bucket = "bucket";
    int height = 0;
    int width = 0;
    // Get the image from an S3 Bucket
    AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
    com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, photo);
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    BufferedImage image = ImageIO.read(inputStream);
    DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)));
    width = image.getWidth();
    height = image.getHeight();
    // Call DetectFaces
    AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient();
    DetectFacesResult result = amazonRekognition.detectFaces(request);
    // Show the bounding box info for each face.
    List<FaceDetail> faceDetails = result.getFaceDetails();
    for (FaceDetail face : faceDetails) {
        BoundingBox box = face.getBoundingBox();
        float left = width * box.getLeft();
        float top = height * box.getTop();
        System.out.println("Face:");
        System.out.println("Left: " + String.valueOf((int) left));
        System.out.println("Top: " + String.valueOf((int) top));
        System.out.println("Face Width: " + String.valueOf((int) (width * box.getWidth())));
        System.out.println("Face Height: " + String.valueOf((int) (height * box.getHeight())));
        System.out.println();
    }
    // Create frame and panel.
    JFrame frame = new JFrame("RotateImage");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DisplayFaces panel = new DisplayFaces(result, image);
    panel.setPreferredSize(new Dimension(image.getWidth() / scale, image.getHeight() / scale));
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) BufferedImage(java.awt.image.BufferedImage) Image(com.amazonaws.services.rekognition.model.Image) BufferedImage(java.awt.image.BufferedImage) FaceDetail(com.amazonaws.services.rekognition.model.FaceDetail) BoundingBox(com.amazonaws.services.rekognition.model.BoundingBox) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) DetectFacesResult(com.amazonaws.services.rekognition.model.DetectFacesResult) DetectFacesRequest(com.amazonaws.services.rekognition.model.DetectFacesRequest)

Example 8 with AmazonS3ClientBuilder.defaultClient

use of com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient in project aws-doc-sdk-examples by awsdocs.

the class ExportEndpoints method downloadFromS3.

public static void downloadFromS3(String s3BucketName, List<String> objectKeys, String downloadDirectory) {
    // Initializes the Amazon S3 client.
    AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
    try {
        // Downloads each object to the specified file path.
        for (String key : objectKeys) {
            S3Object object = s3Client.getObject(s3BucketName, key);
            String endpointsFileName = key.substring(key.lastIndexOf("/"));
            Path filePath = Paths.get(downloadDirectory + endpointsFileName);
            System.out.format("Downloading %s to %s . . .\n", filePath.getFileName(), filePath.getParent());
            writeObjectToFile(filePath, object);
        }
        System.out.println("Download finished.");
    } catch (AmazonServiceException | NullPointerException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : Path(java.nio.file.Path) AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonServiceException(com.amazonaws.AmazonServiceException) S3Object(com.amazonaws.services.s3.model.S3Object)

Example 9 with AmazonS3ClientBuilder.defaultClient

use of com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsVirtualFileTest method testAmpersand.

@Test
@Issue({ "JENKINS-50591", "JCLOUDS-1401" })
public void testAmpersand() throws Exception {
    String key = getPrefix() + "xxx#?:&$'\"<>čॐ";
    try {
        blobStore.putBlob(getContainer(), blobStore.blobBuilder(key).payload("test").build());
        final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
        ListObjectsV2Result result = s3.listObjectsV2(getContainer(), key);
        List<S3ObjectSummary> objects = result.getObjectSummaries();
        assertThat(objects, not(empty()));
        // fails with
        // org.jclouds.rest.AuthorizationException: The request signature we calculated does not match the signature
        // you provided. Check your key and signing method.
        PageSet<? extends StorageMetadata> list = blobStore.list(getContainer(), prefix(key));
        assertThat(list, not(empty()));
    } finally {
        blobStore.removeBlob(getContainer(), key);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 10 with AmazonS3ClientBuilder.defaultClient

use of com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient in project nosqlbench by nosqlbench.

the class S3ClientCache method createAuthorizedClient.

private AmazonS3 createAuthorizedClient(S3UrlFields fields) {
    if (fields.accessKey != null && fields.secretKey != null) {
        AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
        AWSCredentials specialcreds = new BasicAWSCredentials(fields.accessKey, fields.secretKey);
        builder = builder.withCredentials(new AWSStaticCredentialsProvider(specialcreds));
        return builder.build();
    } else {
        return AmazonS3ClientBuilder.defaultClient();
    }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)14 AmazonServiceException (com.amazonaws.AmazonServiceException)7 S3Object (com.amazonaws.services.s3.model.S3Object)3 S3ObjectInfo (com.amazonaws.services.neptune.util.S3ObjectInfo)2 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)2 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 NoSuchEntityException (com.amazonaws.services.identitymanagement.model.NoSuchEntityException)1 AmazonPinpoint (com.amazonaws.services.pinpoint.AmazonPinpoint)1 ExportJournalToS3Result (com.amazonaws.services.qldb.model.ExportJournalToS3Result)1 InvalidParameterException (com.amazonaws.services.qldb.model.InvalidParameterException)1 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 BoundingBox (com.amazonaws.services.rekognition.model.BoundingBox)1