use of com.amazonaws.s3.model.PutObjectRequest in project quality-measure-and-cohort-service by Alvearie.
the class ValueSetImporter method putToS3.
private static void putToS3(ValueSetImporterArguments arguments, FhirContext fhirContext, ValueSet vs, String vsFileName, AmazonS3 S3Client) {
ObjectMetadata metadata = new ObjectMetadata();
byte[] arr = fhirContext.newJsonParser().encodeResourceToString(vs).getBytes();
metadata.setContentLength(arr.length);
PutObjectRequest put = new PutObjectRequest(arguments.bucket, vsFileName, new ByteArrayInputStream(arr), metadata);
S3Client.putObject(put);
}
use of com.amazonaws.s3.model.PutObjectRequest in project entrada by SIDN.
the class S3FileManagerImpl method uploadFile.
private boolean uploadFile(File src, S3Details dstDetails, boolean archive) {
PutObjectRequest request = new PutObjectRequest(dstDetails.getBucket(), FileUtil.appendPath(dstDetails.getKey(), src.getName()), src);
ObjectMetadata meta = new ObjectMetadata();
if (archive) {
meta.setHeader(Headers.STORAGE_CLASS, StorageClass.fromValue(StringUtils.upperCase(archiveStorageClass)));
}
if (encrypt) {
meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
}
request.setMetadata(meta);
try {
amazonS3.putObject(request);
return true;
} catch (Exception e) {
log.error("Error while uploading file: {}", src, e);
}
return false;
}
use of com.amazonaws.s3.model.PutObjectRequest in project datarouter by hotpads.
the class BaseDatarouterS3Client method putObjectAsBytesWithExpirationTime.
@Override
public void putObjectAsBytesWithExpirationTime(String bucket, String key, ContentType contentType, String cacheControl, ObjectCannedACL acl, byte[] bytes, Instant expirationTime) {
S3Client s3Client = getS3ClientForBucket(bucket);
PutObjectRequest request = makePutObjectRequestBuilder(bucket, key, contentType).cacheControl(cacheControl).acl(acl).expires(expirationTime).build();
RequestBody requestBody = RequestBody.fromBytes(bytes);
try (var $ = TracerTool.startSpan("S3 putObject", TraceSpanGroupType.CLOUD_STORAGE)) {
s3Client.putObject(request, requestBody);
TracerTool.appendToSpanInfo("Content-Length", request.contentLength());
}
}
use of com.amazonaws.s3.model.PutObjectRequest in project mapfish-print by mapfish.
the class S3ReportStorage method createPutRequest.
private PutObjectRequest createPutRequest(final String ref, final String filename, final String extension, final String mimeType, final File file) {
final PutObjectRequest request = new PutObjectRequest(bucket, getKey(ref, filename, extension), file);
request.withCannedAcl(CannedAccessControlList.PublicRead);
final ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(mimeType);
request.withMetadata(metadata);
return request;
}
use of com.amazonaws.s3.model.PutObjectRequest in project Synapse-Repository-Services by Sage-Bionetworks.
the class DataUploaderMultipartImpl method uploadDataMultiPart.
@Override
public void uploadDataMultiPart(S3Token s3Token, File dataFile) throws SynapseException {
// Formulate the request, note that S3 does not verify that the entire
// upload matches this md5, unlike the single part upload
String base64Md5;
try {
byte[] encoded = Base64.encodeBase64(Hex.decodeHex(s3Token.getMd5().toCharArray()));
base64Md5 = new String(encoded, "ASCII");
} catch (DecoderException ex) {
throw new SynapseException(ex);
} catch (UnsupportedEncodingException ex) {
throw new SynapseException(ex);
}
ObjectMetadata s3Metadata = new ObjectMetadata();
s3Metadata.setContentType(s3Token.getContentType());
s3Metadata.setContentMD5(base64Md5);
// S3 keys do not start with a slash but sometimes we are storing them
// that way in Synapse
String s3Key = (s3Token.getPath().startsWith("/")) ? s3Token.getPath().substring(1) : s3Token.getPath();
PutObjectRequest request = new PutObjectRequest(s3Token.getBucket(), s3Key, dataFile).withMetadata(s3Metadata);
if (null != progressListener) {
request.setProgressListener(progressListener);
}
request.setCannedAcl(CannedAccessControlList.BucketOwnerFullControl);
// Initiate the multipart uploas
AWSCredentials credentials = new BasicSessionCredentials(s3Token.getAccessKeyId(), s3Token.getSecretAccessKey(), s3Token.getSessionToken());
TransferManager tx = new TransferManager(credentials);
Upload upload = tx.upload(request);
if (null != progressListener) {
progressListener.setUpload(upload);
}
// synchronous, can change it later if we want asynchronous behavior)
try {
upload.waitForUploadResult();
} catch (Exception e) {
throw new SynapseException("AWS S3 multipart upload of " + dataFile + " failed", e);
}
tx.shutdownNow();
}
Aggregations