private PutObjectResult uploadFrom0(final byte[] buffer, RequestMetricCollector requestMetricCollector) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(buffer.length); PutObjectRequest req = new PutObjectRequest(getBucketName(), getKey(), new ByteArrayInputStream(buffer), objectMetadata) .withRequestMetricCollector(requestMetricCollector); return getAmazonS3Client().putObject(req); }
/** * 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; }
STATS.uploadStarted(); PutObjectRequest request = new PutObjectRequest(host, key, tempFile); if (sseEnabled) { switch (sseType) { case KMS: if (sseKmsKeyId != null) { request.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(sseKmsKeyId)); request.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams()); ObjectMetadata metadata = new ObjectMetadata(); metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); request.setMetadata(metadata); break; request.withCannedAcl(aclType); Upload upload = transferManager.upload(request);
@Override public PutObjectRequest decorate(PutObjectRequest request) { final ObjectMetadata objectMetadata = request.getMetadata() == null ? new ObjectMetadata() : request.getMetadata().clone(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); return request.withMetadata(objectMetadata); }
@Override public PutObjectResult putObject(String bucketName, String key, File file) throws SdkClientException, AmazonServiceException { return putObject(new PutObjectRequest(bucketName, key, file) .withMetadata(new ObjectMetadata())); }
@Override public PutObjectResult putObject(String bucketName, String key, File file) throws SdkClientException, AmazonServiceException { return putObject(new PutObjectRequest(bucketName, key, file) .withMetadata(new ObjectMetadata())); }
@Override public PutObjectResult putObject(String bucketName, String key, String content) throws AmazonServiceException, SdkClientException { rejectNull(bucketName, "Bucket name must be provided"); rejectNull(key, "Object key must be provided"); rejectNull(content, "String content must be provided"); byte[] contentBytes = content.getBytes(StringUtils.UTF8); InputStream is = new ByteArrayInputStream(contentBytes); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType("text/plain"); metadata.setContentLength(contentBytes.length); return putObject(new PutObjectRequest(bucketName, key, is, metadata)); }
public PutObjectResult putObject(String bucket, String key, String content) { final InputStream in = new ByteArrayInputStream(StringUtils.toUtf8(content)); return putObject(new PutObjectRequest(bucket, key, in, new ObjectMetadata())); }
public static ObjectMetadata simpleUploadFile(S3Client client, byte[] bytes, String bucket, String key) throws Exception { byte[] md5 = md5(bytes, bytes.length); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.setLastModified(new Date()); metadata.setContentMD5(S3Utils.toBase64(md5)); PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(bytes), metadata); PutObjectResult putObjectResult = client.putObject(putObjectRequest); if ( !putObjectResult.getETag().equals(S3Utils.toHex(md5)) ) { throw new Exception("Unable to match MD5 for config"); } return metadata; } }
try { S3Object object = getS3ObjectAndMetadata(bucket, key, ssecLocal); int sizeOfFile = (int)object.getObjectMetadata().getContentLength(); fieldCount = sizeOfFile/sizeArray; totalSize = sizeOfFile; offset += sizeArray; try (InputStream input = new ByteArrayInputStream(destinationArray)) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(totalSize); PutObjectRequest putObjectRequest = null; if (sseLocal.equals("true")) { metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); putObjectRequest = new PutObjectRequest(bucket, key, input, metadata); } else if (ssecLocal != null) { putObjectRequest = new PutObjectRequest(bucket, key, input, metadata).withSSECustomerKey(ssecLocal); } else { putObjectRequest = new PutObjectRequest(bucket, key, input, metadata); s3Client.putObject(putObjectRequest); if(res.getETag() == null) { return Status.ERROR;
rateLimiter.acquire(chunk.length); ObjectMetadata objectMetadata = getObjectMetadata(localPath); objectMetadata.setContentLength(chunk.length); PutObjectRequest putObjectRequest = new PutObjectRequest( config.getBackupPrefix(), remotePath.toString(), new ByteArrayInputStream(chunk), objectMetadata);
/** * Same as {@link #uploadFrom(byte[])} but allows specifying a request * metric collector. * * @param buffer the byte buffer. * @param requestMetricCollector the request metrics collector. * @return an instance of {@link PutObjectResult} */ public PutObjectResult uploadFrom(final byte[] buffer, RequestMetricCollector requestMetricCollector) { final ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(buffer.length); final PutObjectRequest req = new PutObjectRequest(getBucketName(), getKey(), new ByteArrayInputStream(buffer), objectMetadata) .withRequestMetricCollector(requestMetricCollector); return getAmazonS3Client().putObject(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; }
ObjectMetadata om; if (options.isSyncMetadata()) om = s3MetaFromSyncMeta(obj.getMetadata()); else om = new ObjectMetadata(); if (obj.getMetadata().isDirectory()) om.setContentType(TYPE_DIRECTORY); S3ProgressListener progressListener = null; if (obj.getMetadata().isDirectory()) { req = new PutObjectRequest(config.getBucketName(), targetKey, new ByteArrayInputStream(new byte[0]), om); } else if (file != null) { req = new PutObjectRequest(config.getBucketName(), targetKey, file).withMetadata(om); progressListener = new ByteTransferListener(obj); } else { if (options.isMonitorPerformance()) stream = new ProgressInputStream(stream, new PerformanceListener(getWriteWindow())); req = new PutObjectRequest(config.getBucketName(), targetKey, stream, om); req.setAccessControlList(s3AclFromSyncAcl(obj.getAcl(), options.isIgnoreInvalidAcls())); xferConfig.setMultipartUploadThreshold((long) config.getMpuThresholdMb() * 1024 * 1024); xferConfig.setMinimumUploadPartSize((long) config.getMpuPartSizeMb() * 1024 * 1024); TransferManager xferManager = new TransferManager(s3, Executors.newFixedThreadPool(config.getMpuThreadCount())); xferManager.setConfiguration(xferConfig); final Upload upload = xferManager.upload(req, progressListener); try { String eTag = time(new Callable<String>() {
@Override public PutObjectResult putDirectory(PutDirRequest request) { // Setup permissions CannedAccessControlList perms = request.getPermissions().isPresent() ? request.getPermissions().get() : this.defaultPermissions; // Always zero bytes for an S3 "directory" ByteArrayInputStream in = new ByteArrayInputStream(EMPTY_BYTE_ARRAY); // Convert to a mutable metadata object com.amazonaws.services.s3.model.ObjectMetadata mutable = getAmazonMetadata(request); // Create a mutable request object PutObjectRequest aws = new PutObjectRequest(request.getBucket(), request.getKey(), in, mutable); // Store the perms aws.setCannedAcl(perms); // Make the AWS call, and copy the mutable result into an immutable object return PutObjectResult.copyOf(client.putObject(aws)); }
@Override public void close() throws IOException { if (closed.getAndSet(true)) { return; } mBackupOutputStream.close(); LOG.debug("OutputStream for key '{}' closed. Now beginning upload", mKey); try { final ObjectMetadata om = new ObjectMetadata(); om.setContentLength(mBackupFile.length()); om.setContentType(mContentType); om.setUserMetadata(mMetadata); PutObjectRequest putObjectRequest = new PutObjectRequest(mBucketName, mKey, mBackupFile); putObjectRequest.setMetadata(om); Upload upload = transfers.upload(putObjectRequest); upload.waitForUploadResult(); } catch (InterruptedException e) { throw (InterruptedIOException) new InterruptedIOException(e.toString()) .initCause(e); } catch (AmazonClientException e) { throw new IOException(String.format("saving output %s %s", mKey, e)); } finally { if (!mBackupFile.delete()) { LOG.warn("Could not delete temporary cos file: {}", mBackupOutputStream); } super.close(); } LOG.debug("OutputStream for key '{}' upload complete", mKey); }
final PutObjectRequest request = new PutObjectRequest(bucket, key, in, objectMetadata); request.setStorageClass( StorageClass.valueOf(context.getProperty(STORAGE_CLASS).getValue())); final AccessControlList acl = createACL(context, ff); if (acl != null) { request.setAccessControlList(acl); request.withCannedAcl(cannedAcl); request.setTagging(new ObjectTagging(getObjectTags(context, flowFileCopy))); final PutObjectResult result = s3.putObject(request); if (result.getVersionId() != null) { attributes.put(S3_VERSION_ATTR_KEY, result.getVersionId()); s3.initiateMultipartUpload(initiateRequest); currentState.setUploadId(initiateResult.getUploadId()); currentState.getPartETags().clear(); .withPartSize(thisPartSize); try { UploadPartResult uploadPartResult = s3.uploadPart(uploadRequest); currentState.addPartETag(uploadPartResult.getPartETag()); currentState.setFilePosition(currentState.getFilePosition() + thisPartSize);
ObjectMetadata meta = new ObjectMetadata(); if (mSseEnabled) { meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); meta.setContentMD5(new String(Base64.encode(mHash.digest()))); meta.setContentLength(mFile.length()); PutObjectRequest putReq = new PutObjectRequest(mBucketName, path, mFile).withMetadata(meta); mManager.upload(putReq).waitForUploadResult(); if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath());
private PutObjectRequest createPutObjectRequest(TransferRecord upload) { final File file = new File(upload.file); final PutObjectRequest putObjectRequest = new PutObjectRequest(upload.bucketName, upload.key, file); final ObjectMetadata om = new ObjectMetadata(); om.setContentLength(file.length()); om.setCacheControl(upload.headerCacheControl); putObjectRequest.setStorageClass(upload.headerStorageClass); tagList.add(new Tag(tagParts[0], tagParts[1])); putObjectRequest.setTagging(new ObjectTagging(tagList)); } catch (Exception exception) { LOGGER.error("Error in passing the object tags as request headers.", exception); putObjectRequest.setRedirectLocation(redirectLocation); putObjectRequest.setRequesterPays(REQUESTER_PAYS.equals(isRequesterPays) ? true : false); .setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(upload.sseKMSKey)); putObjectRequest.setMetadata(om); putObjectRequest.setCannedAcl(getCannedAclFromString(upload.cannedAcl));
@Override protected void doPut(String fullPath, ISObject stuff, Map<String, String> attrs) { ObjectMetadata meta = new ObjectMetadata(); meta.setContentType(stuff.getAttribute(ISObject.ATTR_CONTENT_TYPE)); if (!(stuff instanceof SObject.InputStreamSObject)) { long length = stuff.getLength(); if (0 < length) { meta.setContentLength(stuff.getLength()); } } PutObjectRequest req = new PutObjectRequest(bucket, fullPath, stuff.asInputStream(), meta); req.setTagging(mapToTagList(attrs)); StorageClass storageClass = StorageClass.valueOfIgnoreCase(attrs.remove(ATTR_STORAGE_CLASS), defStorageClass); if (null != storageClass) { req.setStorageClass(storageClass.toString()); } req.withCannedAcl(CannedAccessControlList.PublicRead); s3.putObject(req); }