Search in sources :

Example 1 with StorageService

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

the class AWSS3StoragePlugin method uploadInputStream.

@NonNull
@Override
public StorageUploadInputStreamOperation<?> uploadInputStream(@NonNull String key, @NonNull InputStream local, @NonNull StorageUploadInputStreamOptions options, @NonNull Consumer<StorageTransferProgress> onProgress, @NonNull Consumer<StorageUploadInputStreamResult> onSuccess, @NonNull Consumer<StorageException> onError) {
    AWSS3StorageUploadRequest<InputStream> request = new AWSS3StorageUploadRequest<>(key, local, options.getAccessLevel() != null ? options.getAccessLevel() : defaultAccessLevel, options.getTargetIdentityId(), options.getContentType(), options instanceof AWSS3StorageUploadInputStreamOptions ? ((AWSS3StorageUploadInputStreamOptions) options).getServerSideEncryption() : ServerSideEncryption.NONE, options.getMetadata());
    AWSS3StorageUploadInputStreamOperation operation = new AWSS3StorageUploadInputStreamOperation(storageService, cognitoAuthProvider, request, awsS3StoragePluginConfiguration, onProgress, onSuccess, onError);
    operation.start();
    return operation;
}
Also used : AWSS3StorageUploadInputStreamOperation(com.amplifyframework.storage.s3.operation.AWSS3StorageUploadInputStreamOperation) InputStream(java.io.InputStream) AWSS3StorageUploadInputStreamOptions(com.amplifyframework.storage.s3.options.AWSS3StorageUploadInputStreamOptions) AWSS3StorageUploadRequest(com.amplifyframework.storage.s3.request.AWSS3StorageUploadRequest) NonNull(androidx.annotation.NonNull)

Example 2 with StorageService

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

the class AWSS3StoragePlugin method list.

@NonNull
@Override
public StorageListOperation<?> list(@NonNull String path, @NonNull StorageListOptions options, @NonNull Consumer<StorageListResult> onSuccess, @NonNull Consumer<StorageException> onError) {
    AWSS3StorageListRequest request = new AWSS3StorageListRequest(path, options.getAccessLevel() != null ? options.getAccessLevel() : defaultAccessLevel, options.getTargetIdentityId());
    AWSS3StorageListOperation operation = new AWSS3StorageListOperation(storageService, executorService, cognitoAuthProvider, request, awsS3StoragePluginConfiguration, onSuccess, onError);
    operation.start();
    return operation;
}
Also used : AWSS3StorageListOperation(com.amplifyframework.storage.s3.operation.AWSS3StorageListOperation) AWSS3StorageListRequest(com.amplifyframework.storage.s3.request.AWSS3StorageListRequest) NonNull(androidx.annotation.NonNull)

Example 3 with StorageService

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

the class AWSS3StoragePlugin method getUrl.

@NonNull
@Override
public StorageGetUrlOperation<?> getUrl(@NonNull String key, @NonNull StorageGetUrlOptions options, @NonNull Consumer<StorageGetUrlResult> onSuccess, @NonNull Consumer<StorageException> onError) {
    AWSS3StorageGetPresignedUrlRequest request = new AWSS3StorageGetPresignedUrlRequest(key, options.getAccessLevel() != null ? options.getAccessLevel() : defaultAccessLevel, options.getTargetIdentityId(), options.getExpires() != 0 ? options.getExpires() : defaultUrlExpiration);
    AWSS3StorageGetPresignedUrlOperation operation = new AWSS3StorageGetPresignedUrlOperation(storageService, executorService, cognitoAuthProvider, request, awsS3StoragePluginConfiguration, onSuccess, onError);
    operation.start();
    return operation;
}
Also used : AWSS3StorageGetPresignedUrlOperation(com.amplifyframework.storage.s3.operation.AWSS3StorageGetPresignedUrlOperation) AWSS3StorageGetPresignedUrlRequest(com.amplifyframework.storage.s3.request.AWSS3StorageGetPresignedUrlRequest) NonNull(androidx.annotation.NonNull)

Example 4 with StorageService

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

the class AWSS3StoragePlugin method downloadFile.

@NonNull
@Override
public StorageDownloadFileOperation<?> downloadFile(@NonNull String key, @NonNull File local, @NonNull StorageDownloadFileOptions options, @NonNull Consumer<StorageTransferProgress> onProgress, @NonNull Consumer<StorageDownloadFileResult> onSuccess, @NonNull Consumer<StorageException> onError) {
    AWSS3StorageDownloadFileRequest request = new AWSS3StorageDownloadFileRequest(key, local, options.getAccessLevel() != null ? options.getAccessLevel() : defaultAccessLevel, options.getTargetIdentityId());
    AWSS3StorageDownloadFileOperation operation = new AWSS3StorageDownloadFileOperation(storageService, cognitoAuthProvider, request, awsS3StoragePluginConfiguration, onProgress, onSuccess, onError);
    operation.start();
    return operation;
}
Also used : AWSS3StorageDownloadFileRequest(com.amplifyframework.storage.s3.request.AWSS3StorageDownloadFileRequest) AWSS3StorageDownloadFileOperation(com.amplifyframework.storage.s3.operation.AWSS3StorageDownloadFileOperation) NonNull(androidx.annotation.NonNull)

Example 5 with StorageService

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

the class StorageComponentTest method setup.

/**
 * Sets up Storage category by registering a mock AWSS3StoragePlugin
 * instance to Amplify and configuring.
 *
 * @throws AmplifyException if Amplify fails to configure with mock
 *                          Storage category configuration.
 */
@Before
public void setup() throws AmplifyException {
    this.storage = new StorageCategory();
    this.storageService = mock(StorageService.class);
    StorageService.Factory storageServiceFactory = (context, region, bucket) -> storageService;
    CognitoAuthProvider cognitoAuthProvider = mock(CognitoAuthProvider.class);
    doReturn(RandomString.string()).when(cognitoAuthProvider).getIdentityId();
    this.storage.addPlugin(new AWSS3StoragePlugin(storageServiceFactory, cognitoAuthProvider, new AWSS3StoragePluginConfiguration.Builder().build()));
    this.storage.configure(buildConfiguration(), getApplicationContext());
    this.storage.initialize(getApplicationContext());
}
Also used : TransferState(com.amazonaws.mobileconnectors.s3.transferutility.TransferState) AmplifyException(com.amplifyframework.AmplifyException) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) StorageCategory(com.amplifyframework.storage.StorageCategory) StorageDownloadFileResult(com.amplifyframework.storage.result.StorageDownloadFileResult) StorageListResult(com.amplifyframework.storage.result.StorageListResult) URL(java.net.URL) Date(java.util.Date) RunWith(org.junit.runner.RunWith) RandomBytes(com.amplifyframework.testutils.random.RandomBytes) StorageUploadInputStreamResult(com.amplifyframework.storage.result.StorageUploadInputStreamResult) TransferListener(com.amazonaws.mobileconnectors.s3.transferutility.TransferListener) StorageItem(com.amplifyframework.storage.StorageItem) StorageException(com.amplifyframework.storage.StorageException) JSONException(org.json.JSONException) StorageUploadFileResult(com.amplifyframework.storage.result.StorageUploadFileResult) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Mockito.doAnswer(org.mockito.Mockito.doAnswer) StorageService(com.amplifyframework.storage.s3.service.StorageService) AWSS3StoragePluginConfiguration(com.amplifyframework.storage.s3.configuration.AWSS3StoragePluginConfiguration) TransferObserver(com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver) Mockito.anyString(org.mockito.Mockito.anyString) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) MalformedURLException(java.net.MalformedURLException) StorageRemoveResult(com.amplifyframework.storage.result.StorageRemoveResult) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) StorageCategoryConfiguration(com.amplifyframework.storage.StorageCategoryConfiguration) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) Await(com.amplifyframework.testutils.Await) RandomString(com.amplifyframework.testutils.random.RandomString) StorageGetUrlResult(com.amplifyframework.storage.result.StorageGetUrlResult) Mockito.anyInt(org.mockito.Mockito.anyInt) Mockito.any(org.mockito.Mockito.any) RandomTempFile(com.amplifyframework.testutils.random.RandomTempFile) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) StorageCategory(com.amplifyframework.storage.StorageCategory) AWSS3StoragePluginConfiguration(com.amplifyframework.storage.s3.configuration.AWSS3StoragePluginConfiguration) StorageService(com.amplifyframework.storage.s3.service.StorageService) Before(org.junit.Before)

Aggregations

NonNull (androidx.annotation.NonNull)6 AWSS3StorageUploadRequest (com.amplifyframework.storage.s3.request.AWSS3StorageUploadRequest)2 File (java.io.File)2 InputStream (java.io.InputStream)2 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)1 TransferListener (com.amazonaws.mobileconnectors.s3.transferutility.TransferListener)1 TransferObserver (com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver)1 TransferState (com.amazonaws.mobileconnectors.s3.transferutility.TransferState)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 AmplifyException (com.amplifyframework.AmplifyException)1 StorageCategory (com.amplifyframework.storage.StorageCategory)1 StorageCategoryConfiguration (com.amplifyframework.storage.StorageCategoryConfiguration)1 StorageException (com.amplifyframework.storage.StorageException)1 StorageItem (com.amplifyframework.storage.StorageItem)1 StorageDownloadFileResult (com.amplifyframework.storage.result.StorageDownloadFileResult)1 StorageGetUrlResult (com.amplifyframework.storage.result.StorageGetUrlResult)1 StorageListResult (com.amplifyframework.storage.result.StorageListResult)1 StorageRemoveResult (com.amplifyframework.storage.result.StorageRemoveResult)1 StorageUploadFileResult (com.amplifyframework.storage.result.StorageUploadFileResult)1 StorageUploadInputStreamResult (com.amplifyframework.storage.result.StorageUploadInputStreamResult)1