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)
Copy an original file to an Android device.
Upload that file via Amplify.Storage.uploadInputStream(StoragePath.fromString(path), inputStream, StorageUploadInputStreamOptions.defaultInstance(), {}, {}).
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, {}, {})
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)
```
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.
Before opening, please confirm:
Language and Async Model
Kotlin, Kotlin - Coroutines
Amplify Categories
Authentication, Storage
Gradle script dependencies
Environment information
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.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
Reproduction steps (if applicable)
Amplify.Storage.uploadInputStream(StoragePath.fromString(path), inputStream, StorageUploadInputStreamOptions.defaultInstance(), {}, {})
.See description for more details.
Code Snippet
Log output
amplifyconfiguration.json
No response
GraphQL Schema
No response
Additional information and screenshots
No response