use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project tutorials by eugenp.
the class SpringCloudS3IntegrationTest method setupResources.
@BeforeClass
public static void setupResources() throws IOException {
bucketName = UUID.randomUUID().toString();
testFileToDownload = "test-file-download.txt";
testFileToUpload = "test-file-upload.txt";
filesWithSimilarName = new String[] { "foo/hello-apple.txt", "foo/hello-orange.txt", "bar/hello-grapes.txt" };
similarNameFiles = new ArrayList<>();
for (String name : filesWithSimilarName) {
similarNameFiles.add(new File(name.substring(0, name.lastIndexOf("/") + 1)));
}
Files.write(Paths.get(testFileToUpload), "Hello World Uploaded!".getBytes());
AmazonS3 amazonS3 = SpringCloudAwsTestUtil.amazonS3();
amazonS3.createBucket(bucketName);
amazonS3.putObject(bucketName, testFileToDownload, "Hello World");
for (String s3Key : filesWithSimilarName) {
amazonS3.putObject(bucketName, s3Key, "Hello World");
}
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project tutorials by eugenp.
the class SpringCloudS3IntegrationTest method cleanUpResources.
@AfterClass
public static void cleanUpResources() {
AmazonS3 amazonS3 = SpringCloudAwsTestUtil.amazonS3();
ListObjectsV2Result listObjectsV2Result = amazonS3.listObjectsV2(bucketName);
for (S3ObjectSummary objectSummary : listObjectsV2Result.getObjectSummaries()) {
amazonS3.deleteObject(bucketName, objectSummary.getKey());
}
amazonS3.deleteBucket(bucketName);
new File(testFileToDownload).delete();
new File(testFileToUpload).delete();
similarNameFiles.forEach(File::delete);
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project opentest by mcdcorp.
the class GetS3Object method run.
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
String targetFilePath = this.readStringArgument("targetFile");
Boolean overwrite = this.readBooleanArgument("overwrite", false);
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
S3Object object = s3Client.getObject(new GetObjectRequest(bucket, objectKey));
InputStream objectDataStream = object.getObjectContent();
if (targetFilePath != null) {
File targetFile = new File(targetFilePath);
if (!targetFile.isAbsolute()) {
targetFile = Paths.get(this.getActor().getTempDir().getAbsolutePath(), targetFilePath).toFile();
}
targetFile.getParentFile().mkdirs();
try {
if (overwrite) {
Files.copy(objectDataStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else {
Files.copy(objectDataStream, targetFile.toPath());
}
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to transfer data from the input stream into file %s", targetFilePath), ex);
}
this.writeArgument("targetFile", targetFile.getAbsolutePath());
} else {
// TODO: Make targetFile arg optional so this branch can execute.
// Read data in memory and write it to an output value
}
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project opentest by mcdcorp.
the class PutS3Object method run.
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
String sourceFilePath = this.readStringArgument("sourceFile");
File sourceFile = new File(sourceFilePath);
if (sourceFile.exists()) {
try {
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
s3Client.putObject(new PutObjectRequest(bucket, objectKey, sourceFile));
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to upload file \"%s\" to S3 bucket \"%s\"", sourceFilePath, bucket), ex);
}
} else {
throw new RuntimeException(String.format("Source file \"%s\" doesn't exist", sourceFilePath));
}
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project components by Talend.
the class S3Connection method createClient.
public static AmazonS3 createClient(S3DatastoreProperties properties) {
AWSCredentialsProviderChain credentials;
if (properties.specifyCredentials.getValue()) {
credentials = new AWSCredentialsProviderChain(new BasicAWSCredentialsProvider(properties.accessKey.getValue(), properties.secretKey.getValue()), new DefaultAWSCredentialsProviderChain(), new AnonymousAWSCredentialsProvider());
} else {
// do not be polluted by hidden accessKey/secretKey
credentials = new AWSCredentialsProviderChain(new DefaultAWSCredentialsProviderChain(), new AnonymousAWSCredentialsProvider());
}
AmazonS3 conn = new AmazonS3Client(credentials);
return conn;
}
Aggregations