@Test @Deploy("org.nuxeo.ecm.core.storage.binarymanager.s3.tests:OSGI-INF/test-s3directupload-contrib.xml") public void testFails() throws SdkBaseException, InterruptedException { BatchHandler handler = batchManager.getHandler("s3"); try { handler.completeUpload(null, null, new BatchFileInfo("invalid key", null, null, 10, null)); fail("should throw 404"); } catch (AmazonS3Exception e) { assertTrue(e.getMessage().contains("404")); } }
@Override public boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo) { String fileKey = fileInfo.getKey(); ObjectMetadata metadata = amazonS3.getObjectMetadata(bucket, fileKey); String key; if (!useDeDuplication()) { key = StringUtils.removeStart(fileKey, bucketPrefix); } else { key = metadata.getETag(); if (isEmpty(key)) { return false; } String bucketKey = bucketPrefix + key; CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, fileKey, bucket, bucketKey); if (useServerSideEncryption) { if (isNotBlank(serverSideKMSKeyID)) { SSEAwsKeyManagementParams params = new SSEAwsKeyManagementParams(serverSideKMSKeyID); copyObjectRequest.setSSEAwsKeyManagementParams(params); } else { ObjectMetadata newObjectMetadata = new ObjectMetadata(); newObjectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(newObjectMetadata); } } Copy copy = getTransferManager().copy(copyObjectRequest); try { copy.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, fileKey); } metadata = amazonS3.getObjectMetadata(bucket, bucketKey); boolean isMultipartUpload = key.matches(".+-\\d+$"); boolean canDoNonMultipartCopy = metadata.getContentLength() < getTransferManager().getConfiguration() .getMultipartCopyThreshold(); if (isMultipartUpload && canDoNonMultipartCopy) { key = metadata.getETag(); String previousBucketKey = bucketKey; bucketKey = bucketPrefix + key; CopyObjectRequest renameRequest = new CopyObjectRequest(bucket, previousBucketKey, bucket, bucketKey); Copy rename = getTransferManager().copy(renameRequest); try { rename.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, previousBucketKey); } } } BlobInfo blobInfo = new BlobInfo(); blobInfo.mimeType = metadata.getContentType(); blobInfo.encoding = metadata.getContentEncoding(); blobInfo.filename = fileInfo.getFilename(); blobInfo.length = metadata.getContentLength(); blobInfo.key = key; blobInfo.digest = defaultString(metadata.getContentMD5(), metadata.getETag()); Blob blob; try { blob = getBlobProvider().readBlob(blobInfo); } catch (IOException e) { throw new NuxeoException(e); } Batch batch = getBatch(batchId); try { batch.addFile(fileIndex, blob, blob.getFilename(), blob.getMimeType()); } catch (NuxeoException e) { amazonS3.deleteObject(bucket, fileKey); throw e; } return true; }
S3DirectBatchHandler extends AbstractBatchHandler { @Override public boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo) { String fileKey = fileInfo.getKey(); ObjectMetadata metadata = amazonS3.getObjectMetadata(bucket, fileKey); String key; if (!useDeDuplication()) { key = StringUtils.removeStart(fileKey, bucketPrefix); } else { key = metadata.getETag(); if (isEmpty(key)) { return false; } String bucketKey = bucketPrefix + key; CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, fileKey, bucket, bucketKey); if (useServerSideEncryption) { if (isNotBlank(serverSideKMSKeyID)) { SSEAwsKeyManagementParams params = new SSEAwsKeyManagementParams(serverSideKMSKeyID); copyObjectRequest.setSSEAwsKeyManagementParams(params); } else { ObjectMetadata newObjectMetadata = new ObjectMetadata(); newObjectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(newObjectMetadata); } } Copy copy = getTransferManager().copy(copyObjectRequest); try { copy.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, fileKey); } metadata = amazonS3.getObjectMetadata(bucket, bucketKey); boolean isMultipartUpload = key.matches(".+-\\d+$"); boolean canDoNonMultipartCopy = metadata.getContentLength() < getTransferManager().getConfiguration() .getMultipartCopyThreshold(); if (isMultipartUpload && canDoNonMultipartCopy) { key = metadata.getETag(); String previousBucketKey = bucketKey; bucketKey = bucketPrefix + key; CopyObjectRequest renameRequest = new CopyObjectRequest(bucket, previousBucketKey, bucket, bucketKey); Copy rename = getTransferManager().copy(renameRequest); try { rename.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, previousBucketKey); } } } BlobInfo blobInfo = new BlobInfo(); blobInfo.mimeType = metadata.getContentType(); blobInfo.encoding = metadata.getContentEncoding(); blobInfo.filename = fileInfo.getFilename(); blobInfo.length = metadata.getContentLength(); blobInfo.key = key; blobInfo.digest = defaultString(metadata.getContentMD5(), metadata.getETag()); Blob blob; try { blob = getBlobProvider().readBlob(blobInfo); } catch (IOException e) { throw new NuxeoException(e); } Batch batch = getBatch(batchId); try { batch.addFile(fileIndex, blob, blob.getFilename(), blob.getMimeType()); } catch (NuxeoException e) { amazonS3.deleteObject(bucket, fileKey); throw e; } return true; } }
S3DirectBatchHandler extends AbstractBatchHandler { @Override public boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo) { String fileKey = fileInfo.getKey(); ObjectMetadata metadata = amazonS3.getObjectMetadata(bucket, fileKey); String key; if (!useDeDuplication()) { key = StringUtils.removeStart(fileKey, bucketPrefix); } else { key = metadata.getETag(); if (isEmpty(key)) { return false; } String bucketKey = bucketPrefix + key; CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, fileKey, bucket, bucketKey); if (useServerSideEncryption) { if (isNotBlank(serverSideKMSKeyID)) { SSEAwsKeyManagementParams params = new SSEAwsKeyManagementParams(serverSideKMSKeyID); copyObjectRequest.setSSEAwsKeyManagementParams(params); } else { ObjectMetadata newObjectMetadata = new ObjectMetadata(); newObjectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(newObjectMetadata); } } Copy copy = getTransferManager().copy(copyObjectRequest); try { copy.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, fileKey); } metadata = amazonS3.getObjectMetadata(bucket, bucketKey); boolean isMultipartUpload = key.matches(".+-\\d+$"); boolean canDoNonMultipartCopy = metadata.getContentLength() < getTransferManager().getConfiguration() .getMultipartCopyThreshold(); if (isMultipartUpload && canDoNonMultipartCopy) { key = metadata.getETag(); String previousBucketKey = bucketKey; bucketKey = bucketPrefix + key; CopyObjectRequest renameRequest = new CopyObjectRequest(bucket, previousBucketKey, bucket, bucketKey); Copy rename = getTransferManager().copy(renameRequest); try { rename.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, previousBucketKey); } } } BlobInfo blobInfo = new BlobInfo(); blobInfo.mimeType = metadata.getContentType(); blobInfo.encoding = metadata.getContentEncoding(); blobInfo.filename = fileInfo.getFilename(); blobInfo.length = metadata.getContentLength(); blobInfo.key = key; blobInfo.digest = defaultString(metadata.getContentMD5(), metadata.getETag()); Blob blob; try { blob = getBlobProvider().readBlob(blobInfo); } catch (IOException e) { throw new NuxeoException(e); } Batch batch = getBatch(batchId); try { batch.addFile(fileIndex, blob, blob.getFilename(), blob.getMimeType()); } catch (NuxeoException e) { amazonS3.deleteObject(bucket, fileKey); throw e; } return true; }  }
S3DirectBatchHandler extends AbstractBatchHandler { @Override public boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo) { String fileKey = fileInfo.getKey(); ObjectMetadata metadata = amazonS3.getObjectMetadata(bucket, fileKey); String key; if (!useDeDuplication()) { key = StringUtils.removeStart(fileKey, bucketPrefix); } else { key = metadata.getETag(); if (isEmpty(key)) { return false; } String bucketKey = bucketPrefix + key; CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, fileKey, bucket, bucketKey); if (useServerSideEncryption) { if (isNotBlank(serverSideKMSKeyID)) { SSEAwsKeyManagementParams params = new SSEAwsKeyManagementParams(serverSideKMSKeyID); copyObjectRequest.setSSEAwsKeyManagementParams(params); } else { ObjectMetadata newObjectMetadata = new ObjectMetadata(); newObjectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(newObjectMetadata); } } Copy copy = getTransferManager().copy(copyObjectRequest); try { copy.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, fileKey); } metadata = amazonS3.getObjectMetadata(bucket, bucketKey); boolean isMultipartUpload = key.matches(".+-\\d+$"); boolean canDoNonMultipartCopy = metadata.getContentLength() < getTransferManager().getConfiguration() .getMultipartCopyThreshold(); if (isMultipartUpload && canDoNonMultipartCopy) { key = metadata.getETag(); String previousBucketKey = bucketKey; bucketKey = bucketPrefix + key; CopyObjectRequest renameRequest = new CopyObjectRequest(bucket, previousBucketKey, bucket, bucketKey); Copy rename = getTransferManager().copy(renameRequest); try { rename.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, previousBucketKey); } } } BlobInfo blobInfo = new BlobInfo(); blobInfo.mimeType = metadata.getContentType(); blobInfo.encoding = metadata.getContentEncoding(); blobInfo.filename = fileInfo.getFilename(); blobInfo.length = metadata.getContentLength(); blobInfo.key = key; blobInfo.digest = defaultString(metadata.getContentMD5(), metadata.getETag()); Blob blob; try { blob = getBlobProvider().readBlob(blobInfo); } catch (IOException e) { throw new NuxeoException(e); } Batch batch = getBatch(batchId); try { batch.addFile(fileIndex, blob, blob.getFilename(), blob.getMimeType()); } catch (NuxeoException e) { amazonS3.deleteObject(bucket, fileKey); throw e; } return true; }  @Override Batch getBatch(String batchId); @Override boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo); @Override Map<String, Object> refreshToken(String batchId); }
S3DirectBatchHandler extends AbstractBatchHandler { @Override public boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo) { String fileKey = fileInfo.getKey(); ObjectMetadata metadata = amazonS3.getObjectMetadata(bucket, fileKey); String key; if (!useDeDuplication()) { key = StringUtils.removeStart(fileKey, bucketPrefix); } else { key = metadata.getETag(); if (isEmpty(key)) { return false; } String bucketKey = bucketPrefix + key; CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, fileKey, bucket, bucketKey); if (useServerSideEncryption) { if (isNotBlank(serverSideKMSKeyID)) { SSEAwsKeyManagementParams params = new SSEAwsKeyManagementParams(serverSideKMSKeyID); copyObjectRequest.setSSEAwsKeyManagementParams(params); } else { ObjectMetadata newObjectMetadata = new ObjectMetadata(); newObjectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(newObjectMetadata); } } Copy copy = getTransferManager().copy(copyObjectRequest); try { copy.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, fileKey); } metadata = amazonS3.getObjectMetadata(bucket, bucketKey); boolean isMultipartUpload = key.matches(".+-\\d+$"); boolean canDoNonMultipartCopy = metadata.getContentLength() < getTransferManager().getConfiguration() .getMultipartCopyThreshold(); if (isMultipartUpload && canDoNonMultipartCopy) { key = metadata.getETag(); String previousBucketKey = bucketKey; bucketKey = bucketPrefix + key; CopyObjectRequest renameRequest = new CopyObjectRequest(bucket, previousBucketKey, bucket, bucketKey); Copy rename = getTransferManager().copy(renameRequest); try { rename.waitForCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new NuxeoException(e); } finally { amazonS3.deleteObject(bucket, previousBucketKey); } } } BlobInfo blobInfo = new BlobInfo(); blobInfo.mimeType = metadata.getContentType(); blobInfo.encoding = metadata.getContentEncoding(); blobInfo.filename = fileInfo.getFilename(); blobInfo.length = metadata.getContentLength(); blobInfo.key = key; blobInfo.digest = defaultString(metadata.getContentMD5(), metadata.getETag()); Blob blob; try { blob = getBlobProvider().readBlob(blobInfo); } catch (IOException e) { throw new NuxeoException(e); } Batch batch = getBatch(batchId); try { batch.addFile(fileIndex, blob, blob.getFilename(), blob.getMimeType()); } catch (NuxeoException e) { amazonS3.deleteObject(bucket, fileKey); throw e; } return true; }  @Override Batch getBatch(String batchId); @Override boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo); @Override Map<String, Object> refreshToken(String batchId); @Deprecated
    static final String ACCELERATE_MODE_ENABLED_PROPERTY; static final String POLICY_TEMPLATE_PROPERTY; static final String ROLE_ARN_PROPERTY; static final String BLOB_PROVIDER_ID_PROPERTY; static final String INFO_AWS_SECRET_KEY_ID; static final String INFO_AWS_SECRET_ACCESS_KEY; static final String INFO_AWS_SESSION_TOKEN; static final String INFO_BUCKET; static final String INFO_BASE_KEY; static final String INFO_EXPIRATION; static final String INFO_AWS_ENDPOINT; static final String INFO_AWS_PATH_STYLE_ACCESS; static final String INFO_AWS_REGION; static final String INFO_USE_S3_ACCELERATE; }