aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
249 stars 117 forks source link

StoragePath Android not found #2800

Closed mbahmani90 closed 6 months ago

mbahmani90 commented 6 months ago

Before opening, please confirm:

Language and Async Model

Kotlin, Kotlin - Coroutines

Amplify Categories

Storage

Gradle script dependencies

```groovy // Put output below this line implementation 'com.amplifyframework:aws-api:2.14.11' implementation 'com.amplifyframework:aws-datastore:2.14.11' implementation 'com.amplifyframework:core:2.14.11' implementation 'com.amplifyframework:aws-auth-cognito:2.14.11' implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.8.0' implementation("io.github.jan-tennert.supabase:postgrest-kt:0.7.6") implementation("io.ktor:ktor-client-cio:2.3.3") implementation 'com.amplifyframework:aws-storage-s3:2.14.11' implementation "androidx.navigation:navigation-compose:2.7.7" coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' ```

Environment information

``` # Put output below this line - ```

-

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

Hi,

I want to use StoragePath in kotlin android to upload my file in s3 storage. According to https://docs.amplify.aws/android/build-a-backend/storage/storagepath/#create-a-storagepath-from-string I should use the following command. StoragePath.fromString("public/exampleFile.txt")

But StoragePath is not found!

I can store file in s3 without any issue. However, I need StoragePath to store files in specific directory.

Thanks

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

amplifyconfiguration.json

No response

GraphQL Schema

```graphql // Put your schema below this line ```

Additional information and screenshots

No response

tylerjroach commented 6 months ago

@mbahmani90 You need to update the latest version of Amplify (2.16.0) to use StoragePath. The version you have reported does not have it. Instead, you would use the other methods that take a key: String which are marked in documentation as deprecated.

mbahmani90 commented 6 months ago

I update amplify to 2.16.0 and it is now found. However, when I run:

Amplify.Storage.uploadInputStream(StoragePath.fromIdentityId { identityId ->
            "test/${fileName}"
        }, stream, { onComplete() },
            {
                app.l("$it")
                onError() })

I am receiving the following error:

StorageException{message=Something went wrong with your AWS S3 Storage upload InputStream operation, cause=java.lang.Exception: aws.sdk.kotlin.services.s3.model.S3Exception: Access Denied, recoverySuggestion=See attached exception for more information and suggestions}

It is just work fine when I replace:

"test/${fileName}"

with

"private/${identityId}/test/${fileName}"

Thanks

mbahmani90 commented 6 months ago

I had to write

"public/test/${fileName}"

Now it works. :) Many thanks.

tylerjroach commented 6 months ago

@mbahmani90 Thats great! Make sure to follow access control (public/private/protected) guidelines here: https://docs.amplify.aws/android/build-a-backend/storage/storagepath/.

github-actions[bot] commented 6 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.