private void enableS3Encryption(PutObjectRequest uploadRequest) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); uploadRequest.setMetadata(objectMetadata); } }
/** * Updates put request to store the specified instruction object in S3. * * @param req * The put-instruction-file request for the instruction file to * be stored in S3. * @param cekMaterial * The instruction object to be stored in S3. * @return A put request to store the specified instruction object in S3. */ protected final PutObjectRequest updateInstructionPutRequest( PutObjectRequest req, ContentCryptoMaterial cekMaterial) { byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); ObjectMetadata metadata = req.getMetadata(); if (metadata == null) { metadata = new ObjectMetadata(); req.setMetadata(metadata); } // Set the content-length of the upload metadata.setContentLength(bytes.length); // Set the crypto instruction file header metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); // Update the instruction request req.setMetadata(metadata); req.setInputStream(new ByteArrayInputStream(bytes)); // the file attribute in the request is always null before calling this // routine return req; }
ObjectMetadata metadata = new ObjectMetadata(); metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); request.setMetadata(metadata); break;
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) { ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req); // Wraps the object data with a cipher input stream final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial); // Update the metadata req.setMetadata(updateMetadataWithContentCryptoMaterial( req.getMetadata(), req.getFile(), cekMaterial)); // Put the encrypted object into S3 try { return s3.putObject(wrappedReq); } finally { cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log); } }
putObjectRequest.setMetadata(new ObjectMetadata()); ObjectMetadata metadata = putObjectRequest.getMetadata();
/** * Updates put request to store the specified instruction object in S3. * * @param req * The put-instruction-file request for the instruction file to * be stored in S3. * @param cekMaterial * The instruction object to be stored in S3. * @return A put request to store the specified instruction object in S3. */ protected final PutObjectRequest updateInstructionPutRequest( PutObjectRequest req, ContentCryptoMaterial cekMaterial) { final byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); ObjectMetadata metadata = req.getMetadata(); if (metadata == null) { metadata = new ObjectMetadata(); req.setMetadata(metadata); } // Set the content-length of the upload metadata.setContentLength(bytes.length); // Set the crypto instruction file header metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); // Update the instruction request req.setMetadata(metadata); req.setInputStream(new ByteArrayInputStream(bytes)); // the file attribute in the request is always null before calling this // routine return req; }
/** * Creates a put request to store the specified instruction object in S3. * * @param request The put request for the original object to be stored in * S3. * @param instruction The instruction object to be stored in S3. * @return A put request to store the specified instruction object in S3. */ public static PutObjectRequest createInstructionPutRequest(PutObjectRequest request, EncryptionInstruction instruction) { Map<String, String> instructionJSON = convertInstructionToJSONObject(instruction); byte[] instructionBytes = JsonUtils.mapToString(instructionJSON).getBytes(StringUtils.UTF8); InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes); ObjectMetadata metadata = request.getMetadata(); // Set the content-length of the upload metadata.setContentLength(instructionBytes.length); // Set the crypto instruction file header metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); // Update the instruction request request.setKey(request.getKey() + INSTRUCTION_SUFFIX); request.setMetadata(metadata); request.setInputStream(instructionInputStream); return request; }
putObjectRequest.setMetadata(om); putObjectRequest.setCannedAcl(getCannedAclFromString(upload.cannedAcl));
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) { final ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req); // Wraps the object data with a cipher input stream final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial); // Update the metadata req.setMetadata(updateMetadataWithContentCryptoMaterial( req.getMetadata(), req.getFile(), cekMaterial)); // Put the encrypted object into S3 try { return s3.putObject(wrappedReq); } finally { cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log); } }
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, awsFileKey, file); if (metadata != null) { putObjectRequest.setMetadata(metadata); }
/** * Update the request's ObjectMetadata with the necessary information for * decrypting the object * * @param request Non-null PUT request encrypted using the given instruction * @param instruction Non-null instruction used to encrypt the data in this * PUT request. */ public static void updateMetadataWithEncryptionInstruction(PutObjectRequest request, EncryptionInstruction instruction) { byte[] keyBytesToStoreInMetadata = instruction.getEncryptedSymmetricKey(); Cipher symmetricCipher = instruction.getSymmetricCipher(); Map<String, String> materialsDescription = instruction.getMaterialsDescription(); ObjectMetadata metadata = request.getMetadata(); if (metadata == null) metadata = new ObjectMetadata(); if (request.getFile() != null) { Mimetypes mimetypes = Mimetypes.getInstance(); metadata.setContentType(mimetypes.getMimetype(request.getFile())); } updateMetadata(metadata, keyBytesToStoreInMetadata, symmetricCipher, materialsDescription); request.setMetadata(metadata); }
request.setMetadata(metadata);
putObjectRequest.setMetadata(new ObjectMetadata());
public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws AmazonClientException { // Memory problems with large files necessitate writing to disk before // uploading to AWS File cachedFile = cacheLocally(input, key); PutObjectRequest putRequest = new PutObjectRequest(bucketName, key, cachedFile); putRequest.setMetadata(metadata); try { return super.putObject(putRequest); } finally { cachedFile.delete(); } }
final ObjectMetadata metadata = new ObjectMetadata(); metadata.setSSEAlgorithm(SSEAlgorithm.KMS.toString()); putObjectRequest.setMetadata(metadata);
String EXPIRY_DATE = "Mon, Jan 1 2030 11:11:11 GMT"; BasicAWSCredentials awsCreds = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY); AmazonS3Client s3Client = new AmazonS3Client(awsCreds); ResponseHeaderOverrides override = new ResponseHeaderOverrides(); override.setContentType("image/jpeg"); override.setExpires(EXPIRY_DATE); File imageFile = new File(path); PutObjectRequest pros = new PutObjectRequest(BUCKET_NAME, BUCKET_PATH, imageFile); ObjectMetadata meta = new ObjectMetadata(); meta.addUserMetadata("expires", EXPIRY_DATE); meta.setHeader("expires", EXPIRY_DATE); pros.setMetadata(meta); s3Client.putObject(pros);
private PutObjectRequest getAmazonRequest(PutFileRequest request, com.amazonaws.services.s3.model.ObjectMetadata meta) { CannedAccessControlList perms = request.getPermissions().isPresent() ? request.getPermissions().get() : this.defaultPermissions; // Create an AWS request object PutObjectRequest put = new PutObjectRequest(request.getBucket(), request.getKey(), request.getFile()); put.setMetadata(meta); put.setCannedAcl(perms); return put; }
@Override public Transfer performTransfer(TransferManager transferManager) { // Get a handle to the local file. File localFile = new File(params.getLocalPath()); // Create and prepare the metadata. ObjectMetadata metadata = new ObjectMetadata(); prepareMetadata(params, metadata); // Create a put request and a transfer manager with the parameters and the metadata. PutObjectRequest putObjectRequest = new PutObjectRequest(params.getS3BucketName(), params.getS3KeyPrefix(), localFile); putObjectRequest.setMetadata(metadata); return s3Operations.upload(putObjectRequest, transferManager); } });
@Override public void upload(S3InputObjectInterface s3Object) throws AmazonClientException { PutObjectRequest request = new PutObjectRequest(s3Object.bucket(), s3Object.key(), new File(s3Object.localUri())); ObjectMetadata metadata = new ObjectMetadata(); metadata.addUserMetadata("Content-Type", s3Object.mimeType()); request.setMetadata(metadata); request.setFile(new File(s3Object.localUri())); s3Client.putObject(request); }
from.setCannedAcl(CannedAccessControlList.Private); from.setInputStream(System.in); from.setMetadata(metadata); from.setSSECustomerKey(sseKey); from.setRedirectLocation("redirectLocation");