Search in sources :

Example 1 with UploadImpl

use of com.amazonaws.services.s3.transfer.internal.UploadImpl in project herd by FINRAOS.

the class MockS3OperationsImpl method upload.

@Override
public Upload upload(PutObjectRequest putObjectRequest, TransferManager transferManager) {
    LOGGER.debug("upload(): putObjectRequest.getBucketName() = " + putObjectRequest.getBucketName() + ", putObjectRequest.getKey() = " + putObjectRequest.getKey());
    putObject(putObjectRequest, transferManager.getAmazonS3Client());
    long contentLength = putObjectRequest.getFile().length();
    TransferProgress progress = new TransferProgress();
    progress.setTotalBytesToTransfer(contentLength);
    progress.updateProgress(contentLength);
    UploadImpl upload = new UploadImpl(null, progress, null, null);
    upload.setState(TransferState.Completed);
    return upload;
}
Also used : MultipleFileUploadImpl(com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl) UploadImpl(com.amazonaws.services.s3.transfer.internal.UploadImpl) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress)

Example 2 with UploadImpl

use of com.amazonaws.services.s3.transfer.internal.UploadImpl 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;
}
Also used : MultipleFileUploadImpl(com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl) ArrayList(java.util.ArrayList) Upload(com.amazonaws.services.s3.transfer.Upload) MultipartUpload(com.amazonaws.services.s3.model.MultipartUpload) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) MultipleFileUploadImpl(com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl) UploadImpl(com.amazonaws.services.s3.transfer.internal.UploadImpl) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress)

Aggregations

TransferProgress (com.amazonaws.services.s3.transfer.TransferProgress)2 MultipleFileUploadImpl (com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl)2 UploadImpl (com.amazonaws.services.s3.transfer.internal.UploadImpl)2 MultipartUpload (com.amazonaws.services.s3.model.MultipartUpload)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 MultipleFileUpload (com.amazonaws.services.s3.transfer.MultipleFileUpload)1 Upload (com.amazonaws.services.s3.transfer.Upload)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1