Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageException/S3Exception: Something went wrong with your AWS S3 Storage download file operation/The requested range is not satisfiable #2938

Open
1 task done
Orbyt opened this issue Oct 11, 2024 · 1 comment
Labels
bug Something isn't working storage Related to the Storage category/plugins

Comments

@Orbyt
Copy link

Orbyt commented Oct 11, 2024

Before opening, please confirm:

Language and Async Model

Kotlin, Kotlin - Coroutines

Amplify Categories

Authentication, Storage

Gradle script dependencies

implementation("com.amplifyframework.ui:authenticator:1.2.0")
// Issue still present on latest (2.23.0).
implementation("com.amplifyframework:aws-storage-s3:2.19.1")
implementation("com.amplifyframework:aws-storage-s3:2.23.0")

Environment information

------------------------------------------------------------
Gradle 8.7
------------------------------------------------------------
Kotlin:       1.9.22
Groovy:       3.0.17

Please include any relevant guides or documentation you're referencing

Amplify documentation

Describe the bug

Amplify throws an StorageException when attempting to download a file with the same name to the same location where the original file was uploaded.

val downloadsDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
// This is simply the file name from the path used to download the file.
// For example, if path = "/customers/12345/some_file.pdf", this will equal "some_file.pdf".
val fileNameFromPath = path.split("/").last()
val file = File(downloadsDirectory,"$fileNameFromPath")
Amplify.Storage.downloadFile(StoragePath.fromString(path), file, { 
     // Success.
},{
     // Failure.
})

The SDK has no problem overwriting a file with the same name in the same location that was already downloaded via the SDK. This issue is only present when an original file is uploaded from some location on the files (e.g. "downloads") and when, immediately afterwards, the SDK attempts to download that file from S3 to the same location with the same file name.

Stack trace

DownloadWorker failed with exception: aws.sdk.kotlin.services.s3.model.S3Exception: The requested range is not satisfiable, Request ID: ...., Extended request ID: .....
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializerKt.throwGetObjectError(GetObjectOperationDeserializer.kt:115)
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializerKt.access$throwGetObjectError(GetObjectOperationDeserializer.kt:1)
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializer.deserialize(GetObjectOperationDeserializer.kt:36)
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializer$deserialize$1.invokeSuspend(Unknown Source:15)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)
StorageException{message=Something went wrong with your AWS S3 Storage download file operation, cause=java.lang.Exception: aws.sdk.kotlin.services.s3.model.S3Exception: The requested range is not satisfiable, Request ID: ....., Extended request ID: ....., recoverySuggestion=See attached exception for more information and suggestions}
    at com.amplifyframework.storage.s3.operation.AWSS3StoragePathDownloadFileOperation$DownloadTransferListener.onError(AWSS3StoragePathDownloadFileOperation.kt:215)
    at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater.updateOnError$lambda$11$lambda$10(TransferStatusUpdater.kt:153)
    at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater.$r8$lambda$n0J6tXM7pCeBPukpFjIOUA1Z_dE(Unknown Source:0)
    at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8705)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Caused by: java.lang.Exception: aws.sdk.kotlin.services.s3.model.S3Exception: The requested range is not satisfiable, Request ID: .... , Extended request ID: .....
    at com.amplifyframework.storage.s3.transfer.worker.BaseTransferWorker.doWork$suspendImpl(BaseTransferWorker.kt:120)
    at com.amplifyframework.storage.s3.transfer.worker.BaseTransferWorker$doWork$1.invokeSuspend(Unknown Source:14)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:266)
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:99)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:266)
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:99)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)

Reproduction steps (if applicable)

  1. Copy an original file to an Android device.
  2. Upload that file via Amplify.Storage.uploadInputStream(StoragePath.fromString(path), inputStream, StorageUploadInputStreamOptions.defaultInstance(), {}, {}).
  3. Afterwards, download that same file using the same path to the same directory on the device that the file was originally uploaded from:
val fileNameFromPath = path.split("/").last()
val file = File(downloadsDirectory,"$fileNameFromPath")
Amplify.Storage.downloadFile(StoragePath.fromString(path), file, {}, {})
  1. Observe the error.

See description for more details.

Code Snippet

// Upload a file from a directory, such as a downloads directory.
Amplify.Storage.uploadInputStream(StoragePath.fromString(path), inputStream, StorageUploadInputStreamOptions.defaultInstance(), {}, {})

// Download file to same directory file was uploaded from.
val downloadsDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
// This is simply the file name from the path used to download the file.
// For example, if path = "/customers/12345/some_file.pdf", this will equal "some_file.pdf".
val fileNameFromPath = path.split("/").last()
val file = File(downloadsDirectory,"$fileNameFromPath")
Amplify.Storage.downloadFile(StoragePath.fromString(path), file, { 
     // Success.
},{
     // Failure.
})

Log output

DownloadWorker failed with exception: aws.sdk.kotlin.services.s3.model.S3Exception: The requested range is not satisfiable, Request ID: ...., Extended request ID: .....
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializerKt.throwGetObjectError(GetObjectOperationDeserializer.kt:115)
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializerKt.access$throwGetObjectError(GetObjectOperationDeserializer.kt:1)
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializer.deserialize(GetObjectOperationDeserializer.kt:36)
    at aws.sdk.kotlin.services.s3.serde.GetObjectOperationDeserializer$deserialize$1.invokeSuspend(Unknown Source:15)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)
StorageException{message=Something went wrong with your AWS S3 Storage download file operation, cause=java.lang.Exception: aws.sdk.kotlin.services.s3.model.S3Exception: The requested range is not satisfiable, Request ID: ....., Extended request ID: ....., recoverySuggestion=See attached exception for more information and suggestions}
    at com.amplifyframework.storage.s3.operation.AWSS3StoragePathDownloadFileOperation$DownloadTransferListener.onError(AWSS3StoragePathDownloadFileOperation.kt:215)
    at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater.updateOnError$lambda$11$lambda$10(TransferStatusUpdater.kt:153)
    at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater.$r8$lambda$n0J6tXM7pCeBPukpFjIOUA1Z_dE(Unknown Source:0)
    at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8705)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Caused by: java.lang.Exception: aws.sdk.kotlin.services.s3.model.S3Exception: The requested range is not satisfiable, Request ID: .... , Extended request ID: .....
    at com.amplifyframework.storage.s3.transfer.worker.BaseTransferWorker.doWork$suspendImpl(BaseTransferWorker.kt:120)
    at com.amplifyframework.storage.s3.transfer.worker.BaseTransferWorker$doWork$1.invokeSuspend(Unknown Source:14)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:266)
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:99)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:266)
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:99)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)

amplifyconfiguration.json

No response

GraphQL Schema

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Oct 11, 2024
@mattcreaser mattcreaser added bug Something isn't working storage Related to the Storage category/plugins labels Oct 11, 2024
@github-actions github-actions bot removed the pending-triage Issue is pending triage label Oct 11, 2024
@mattcreaser
Copy link
Member

Thanks for the detailed description of the issue @Orbyt. The bug you've described is quite surprising - we will need to try to reproduce and investigate.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working storage Related to the Storage category/plugins
Projects
None yet
Development

No branches or pull requests

2 participants