Search in sources :

Example 1 with ServerSideEncryption

use of com.amplifyframework.storage.s3.ServerSideEncryption in project amplify-android by aws-amplify.

the class AWSS3StorageUploadFileOperation method start.

@SuppressLint("SyntheticAccessor")
@Override
public void start() {
    // Only start if it hasn't already been started
    if (transferObserver != null) {
        return;
    }
    // Grab the file to upload...
    File file = getRequest().getLocal();
    // Set up the metadata
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setUserMetadata(getRequest().getMetadata());
    objectMetadata.setContentType(getRequest().getContentType());
    ServerSideEncryption storageServerSideEncryption = getRequest().getServerSideEncryption();
    if (!ServerSideEncryption.NONE.equals(storageServerSideEncryption)) {
        objectMetadata.setSSEAlgorithm(storageServerSideEncryption.getName());
    }
    // Upload!
    awsS3StoragePluginConfiguration.getAWSS3PluginPrefixResolver(cognitoAuthProvider).resolvePrefix(getRequest().getAccessLevel(), getRequest().getTargetIdentityId(), prefix -> {
        try {
            String serviceKey = prefix.concat(getRequest().getKey());
            transferObserver = storageService.uploadFile(serviceKey, file, objectMetadata);
            transferObserver.setTransferListener(new UploadTransferListener());
        } catch (Exception exception) {
            onError.accept(new StorageException("Issue uploading file.", exception, "See included exception for more details and suggestions to fix."));
        }
    }, onError);
}
Also used : ServerSideEncryption(com.amplifyframework.storage.s3.ServerSideEncryption) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) StorageException(com.amplifyframework.storage.StorageException) StorageException(com.amplifyframework.storage.StorageException) SuppressLint(android.annotation.SuppressLint)

Example 2 with ServerSideEncryption

use of com.amplifyframework.storage.s3.ServerSideEncryption in project amplify-android by aws-amplify.

the class AWSS3StorageUploadInputStreamOperation method start.

@SuppressLint("SyntheticAccessor")
@Override
public void start() {
    // Only start if it hasn't already been started
    if (transferObserver != null) {
        return;
    }
    // Grab the inputStream to upload...
    InputStream inputStream = getRequest().getLocal();
    // Set up the metadata
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setUserMetadata(getRequest().getMetadata());
    objectMetadata.setContentType(getRequest().getContentType());
    ServerSideEncryption storageServerSideEncryption = getRequest().getServerSideEncryption();
    if (!ServerSideEncryption.NONE.equals(storageServerSideEncryption)) {
        objectMetadata.setSSEAlgorithm(storageServerSideEncryption.getName());
    }
    awsS3StoragePluginConfiguration.getAWSS3PluginPrefixResolver(cognitoAuthProvider).resolvePrefix(getRequest().getAccessLevel(), getRequest().getTargetIdentityId(), prefix -> {
        try {
            String serviceKey = prefix.concat(getRequest().getKey());
            transferObserver = storageService.uploadInputStream(serviceKey, inputStream, objectMetadata);
            transferObserver.setTransferListener(new UploadTransferListener());
        } catch (IOException ioException) {
            onError.accept(new StorageException("Issue uploading inputStream.", ioException, "See included exception for more details and suggestions to fix."));
        }
    }, onError);
}
Also used : InputStream(java.io.InputStream) ServerSideEncryption(com.amplifyframework.storage.s3.ServerSideEncryption) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) StorageException(com.amplifyframework.storage.StorageException) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 StorageException (com.amplifyframework.storage.StorageException)2 ServerSideEncryption (com.amplifyframework.storage.s3.ServerSideEncryption)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1