use of com.amazonaws.services.s3.transfer.ObjectMetadataProvider in project herd by FINRAOS.
the class S3DaoImpl method uploadFileList.
@Override
public S3FileTransferResultsDto uploadFileList(final S3FileTransferRequestParamsDto params) throws InterruptedException {
LOGGER.info("Uploading a list of files from the local directory to S3... localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={}", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), params.getFiles().size());
if (LOGGER.isInfoEnabled()) {
for (File file : params.getFiles()) {
LOGGER.info("s3Key=\"{}\"", file.getPath());
}
}
// Perform the transfer.
S3FileTransferResultsDto results = performTransfer(params, new Transferer() {
@Override
public Transfer performTransfer(TransferManager transferManager) {
return s3Operations.uploadFileList(params.getS3BucketName(), params.getS3KeyPrefix(), new File(params.getLocalPath()), params.getFiles(), new ObjectMetadataProvider() {
@Override
public void provideObjectMetadata(File file, ObjectMetadata metadata) {
prepareMetadata(params, metadata);
}
}, transferManager);
}
});
LOGGER.info("Uploaded list of files from the local directory to S3. " + "localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={} totalBytesTransferred={} transferDuration=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), results.getTotalFilesTransferred(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
logOverallTransferRate(results);
return results;
}
use of com.amazonaws.services.s3.transfer.ObjectMetadataProvider in project herd by FINRAOS.
the class S3DaoImpl method uploadDirectory.
@Override
public S3FileTransferResultsDto uploadDirectory(final S3FileTransferRequestParamsDto params) throws InterruptedException {
LOGGER.info("Uploading local directory to S3... localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName());
// Perform the transfer.
S3FileTransferResultsDto results = performTransfer(params, new Transferer() {
@Override
public Transfer performTransfer(TransferManager transferManager) {
return s3Operations.uploadDirectory(params.getS3BucketName(), params.getS3KeyPrefix(), new File(params.getLocalPath()), params.isRecursive(), new ObjectMetadataProvider() {
@Override
public void provideObjectMetadata(File file, ObjectMetadata metadata) {
prepareMetadata(params, metadata);
}
}, transferManager);
}
});
LOGGER.info("Uploaded local directory to S3. " + "localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={} totalBytesTransferred={} transferDuration=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), results.getTotalFilesTransferred(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
logOverallTransferRate(results);
return results;
}
use of com.amazonaws.services.s3.transfer.ObjectMetadataProvider in project herd by FINRAOS.
the class MockS3OperationsImpl method uploadFileList.
@Override
public MultipleFileUpload uploadFileList(String bucketName, String virtualDirectoryKeyPrefix, File directory, List<File> files, ObjectMetadataProvider metadataProvider, TransferManager transferManager) {
LOGGER.debug("uploadFileList(): bucketName = " + bucketName + ", virtualDirectoryKeyPrefix = " + virtualDirectoryKeyPrefix + ", directory = " + directory + ", files = " + files);
String directoryPath = directory.getAbsolutePath();
long totalFileLength = 0;
List<Upload> subTransfers = new ArrayList<>();
for (File file : files) {
// Get path to file relative to the specified directory
String relativeFilePath = file.getAbsolutePath().substring(directoryPath.length());
// Replace any backslashes (i.e. Windows separator) with a forward slash.
relativeFilePath = relativeFilePath.replace("\\", "/");
// Remove any leading slashes
relativeFilePath = relativeFilePath.replaceAll("^/+", "");
long fileLength = file.length();
// Remove any trailing slashes
virtualDirectoryKeyPrefix = virtualDirectoryKeyPrefix.replaceAll("/+$", "");
String s3ObjectKey = virtualDirectoryKeyPrefix + "/" + relativeFilePath;
totalFileLength += fileLength;
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3ObjectKey, file);
ObjectMetadata objectMetadata = new ObjectMetadata();
metadataProvider.provideObjectMetadata(null, objectMetadata);
putObjectRequest.setMetadata(objectMetadata);
putObject(putObjectRequest, transferManager.getAmazonS3Client());
subTransfers.add(new UploadImpl(null, null, null, null));
}
TransferProgress progress = new TransferProgress();
progress.setTotalBytesToTransfer(totalFileLength);
progress.updateProgress(totalFileLength);
MultipleFileUploadImpl multipleFileUpload = new MultipleFileUploadImpl(null, progress, null, virtualDirectoryKeyPrefix, bucketName, subTransfers);
multipleFileUpload.setState(TransferState.Completed);
return multipleFileUpload;
}
Aggregations