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);
}
}
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);
}
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);
}
}
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);
}
}
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();
}
}
Aggregations