use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project nifi by apache.
the class AbstractS3IT method putTestFile.
protected void putTestFile(String key, File file) throws AmazonS3Exception {
PutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, key, file);
client.putObject(putRequest);
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project nifi by apache.
the class AbstractS3IT method putTestFileEncrypted.
protected void putTestFileEncrypted(String key, File file) throws AmazonS3Exception, FileNotFoundException {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
PutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, key, new FileInputStream(file), objectMetadata);
client.putObject(putRequest);
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest 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 software.amazon.awssdk.services.s3.model.PutObjectRequest in project apex-malhar by apache.
the class S3Reconciler method processCommittedData.
/**
* Uploads the file on Amazon S3 using putObject API from S3 client
*/
@Override
protected void processCommittedData(FSRecordCompactionOperator.OutputMetaData outputMetaData) {
try {
Path path = new Path(outputMetaData.getPath());
if (fs.exists(path) == false) {
logger.debug("Ignoring non-existent path assuming replay : {}", path);
return;
}
FSDataInputStream fsinput = fs.open(path);
ObjectMetadata omd = new ObjectMetadata();
omd.setContentLength(outputMetaData.getSize());
String keyName = directoryName + Path.SEPARATOR + outputMetaData.getFileName();
PutObjectRequest request = new PutObjectRequest(bucketName, keyName, fsinput, omd);
if (outputMetaData.getSize() < Integer.MAX_VALUE) {
request.getRequestClientOptions().setReadLimit((int) outputMetaData.getSize());
} else {
throw new RuntimeException("PutRequestSize greater than Integer.MAX_VALUE");
}
if (fs.exists(path)) {
PutObjectResult result = s3client.putObject(request);
logger.debug("File {} Uploaded at {}", keyName, result.getETag());
}
} catch (FileNotFoundException e) {
logger.debug("Ignoring non-existent path assuming replay : {}", outputMetaData.getPath());
} catch (IOException e) {
logger.error("Unable to create Stream: {}", e.getMessage());
}
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project apex-malhar by apache.
the class S3InputModuleAppTest method setup.
@Before
public void setup() throws Exception {
client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
client.createBucket(testMeta.bucketKey);
inputDir = testMeta.baseDirectory + File.separator + "input";
outputDir = testMeta.baseDirectory + File.separator + "output";
File file1 = new File(inputDir + File.separator + FILE_1);
File file2 = new File(inputDir + File.separator + FILE_2);
FileUtils.writeStringToFile(file1, FILE_1_DATA);
FileUtils.writeStringToFile(file2, FILE_2_DATA);
client.putObject(new PutObjectRequest(testMeta.bucketKey, "input/" + FILE_1, file1));
client.putObject(new PutObjectRequest(testMeta.bucketKey, "input/" + FILE_2, file2));
files = SCHEME + "://" + accessKey + ":" + secretKey + "@" + testMeta.bucketKey + "/input";
}
Aggregations