use of com.amazonaws.services.s3.model.PutObjectRequest in project airpal by airbnb.
the class S3FilePersistor method persist.
@Override
public URI persist(JobOutputBuilder outputBuilder, Job job) {
File file = checkNotNull(outputBuilder.build(), "output builder resulting file was null");
val objectMetaData = new ObjectMetadata();
objectMetaData.setContentLength(file.length());
objectMetaData.setContentType(MediaType.CSV_UTF_8.toString());
if (compressedOutput) {
objectMetaData.setContentEncoding("gzip");
}
val putRequest = new PutObjectRequest(outputBucket, getOutputKey(file.getName()), file).withMetadata(objectMetaData);
try {
s3Client.putObject(putRequest);
return UriBuilder.fromPath("/api/s3/{filename}").build(file.getName());
} catch (AmazonClientException e) {
throw new ExecutionClient.ExecutionFailureException(job, "Could not upload CSV to S3", e);
} finally {
outputBuilder.delete();
}
}
use of com.amazonaws.services.s3.model.PutObjectRequest in project exhibitor by soabase.
the class S3PseudoLock method createFile.
@Override
protected void createFile(String key, byte[] contents) throws Exception {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(contents.length);
PutObjectRequest request = new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), metadata);
client.putObject(request);
}
use of com.amazonaws.services.s3.model.PutObjectRequest in project exhibitor by soabase.
the class TestS3BackupProviderBase method testDownload.
@Test
public void testDownload() throws Exception {
InputStream in = null;
OutputStream out = null;
File tempFile = File.createTempFile("test", ".test");
try {
in = new FileInputStream(sourceFile);
PutObjectRequest dummyRequest = new PutObjectRequest("bucket", "exhibitor-backup" + S3BackupProvider.SEPARATOR + "test" + S3BackupProvider.SEPARATOR + 1, in, null);
MockS3Client s3Client = new MockS3Client(null, null);
s3Client.putObject(dummyRequest);
S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
out = new FileOutputStream(tempFile);
provider.downloadBackup(null, new BackupMetaData("test", 1), out, Maps.<String, String>newHashMap());
Assert.assertEquals(Files.toByteArray(sourceFile), Files.toByteArray(tempFile));
} finally {
CloseableUtils.closeQuietly(in);
CloseableUtils.closeQuietly(out);
//noinspection ResultOfMethodCallIgnored
tempFile.delete();
}
}
use of com.amazonaws.services.s3.model.PutObjectRequest in project gradle by gradle.
the class S3Client method put.
public void put(InputStream inputStream, Long contentLength, URI destination) {
checkRequiredJigsawModuleIsOnPath();
try {
S3RegionalResource s3RegionalResource = new S3RegionalResource(destination);
String bucketName = s3RegionalResource.getBucketName();
String s3BucketKey = s3RegionalResource.getKey();
configureClient(s3RegionalResource);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(contentLength);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3BucketKey, inputStream, objectMetadata);
LOGGER.debug("Attempting to put resource:[{}] into s3 bucket [{}]", s3BucketKey, bucketName);
amazonS3Client.putObject(putObjectRequest);
} catch (AmazonClientException e) {
throw ResourceExceptions.putFailed(destination, e);
}
}
use of com.amazonaws.services.s3.model.PutObjectRequest in project alluxio by Alluxio.
the class S3AUnderFileSystem method createEmptyObject.
@Override
protected boolean createEmptyObject(String key) {
try {
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(0);
meta.setContentMD5(DIR_HASH);
meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
mClient.putObject(new PutObjectRequest(mBucketName, key, new ByteArrayInputStream(new byte[0]), meta));
return true;
} catch (AmazonClientException e) {
LOG.error("Failed to create object: {}", key, e);
return false;
}
}
Aggregations