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

TransferUtility can't read awsconfiguration.json region attribute #2784

Closed
taouichaimaa opened this issue Jan 31, 2022 · 5 comments
Closed
Labels
pending-community-response Issue is pending response from the issue requestor question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3).

Comments

@taouichaimaa
Copy link

taouichaimaa commented Jan 31, 2022

Describe the bug
I'm trying to upload a file into my s3 bucket using transferUtility , I've added the

"S3TransferUtility": {
        "Default": {
            "Bucket": "bucket-deployment",
            "Region": "us-region"
        }
    }

section to my awsconfiguration.json but I keep getting:

java.lang.IllegalArgumentException: Failed to read S3TransferUtility please check your setup or awsconfiguration.json file
      at com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility$Builder.build(TransferUtility.java:292)

this is the code i use for uploading:

fun setAmazonS3Client() {
        s3 = AmazonS3Client(AWSMobileClient.getInstance().awsCredentials, Region.getRegion(Regions.US_REGION))

    }
    fun setTransferUtility() {
        transferUtility = TransferUtility.builder()
            .context(requireContext())
            .awsConfiguration(AWSMobileClient.getInstance().configuration)
            .s3Client(s3)
            .build()

    }
 fun upload(transferUtility: TransferUtility,fileKey:String,filename:File) {
 val observer: TransferObserver = transferUtility.upload(
     "bucket-deployment",
            fileKey,
          filename,
            CannedAccessControlList.PublicRead
        )
        observer.setTransferListener(object : TransferListener {
            override fun onStateChanged(id: Int, state: TransferState) {
                if (state == TransferState.COMPLETED) {
                    Log.i("state changed", state.toString() + "")
                } else if (state == TransferState.FAILED) {
                    Log.e("state changed", state.toString() + "")
                }
            }

            override fun onProgressChanged(id: Int, bytesCurrent: Long, bytesTotal: Long) {
                val percentDonef = bytesCurrent.toFloat() / bytesTotal.toFloat() * 100
                val percentDone = percentDonef.toInt()

                Log.d(
                    "TransferProg", "ID:$id bytesCurrent: " + bytesCurrent
                        .toString() + " bytesTotal: " + bytesTotal.toString() + " " + percentDone.toString() + "%"
                )
            }
            override fun onError(id: Int, ex: Exception) {
                Log.e("state changed", ex.toString() + "")
            }
        })
    }

To Reproduce
A code sample or steps:

view above

Which AWS service(s) are affected?

Expected behavior
read from awsConfiguration.json

Screenshots
If applicable, add screenshots to help explain your problem.

Environment Information (please complete the following information):

  • AWS Android SDK Version: [ 2.38.0]
  • Device: [physical device
  • Android Version: [11]
  • Specific to simulators: [No]

Additional context
Add any other context about the problem here.

@taouichaimaa taouichaimaa changed the title TransferUsability can't read awsconfiguration.json region attribute TransferUtility can't read awsconfiguration.json region attribute Jan 31, 2022
@eeatonaws eeatonaws added question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3). labels Jan 31, 2022
@eeatonaws
Copy link
Contributor

eeatonaws commented Jan 31, 2022

Hi @taouichaimaa, US_REGION is not one of the regions defined in Regions. Please use one of the regions in Regions.java, located here in awsconfiguration.json and when creating the AmazonS3Client.

@eeatonaws eeatonaws added the closing soon Issue will auto-close if there is no additional activity within 7 days. label Jan 31, 2022
@taouichaimaa
Copy link
Author

Hi, in reality I have us-east-1 in my config file , I just put that for security sake.

@eeatonaws eeatonaws removed the closing soon Issue will auto-close if there is no additional activity within 7 days. label Feb 1, 2022
@eeatonaws
Copy link
Contributor

@taouichaimaa, thanks for clarifying. Could you provide the full stack trace? This will help us determine which part of TransferUtility.Builder.build() is causing the exception to be thrown.

@eeatonaws eeatonaws added the pending-community-response Issue is pending response from the issue requestor label Feb 1, 2022
@gpanshu
Copy link
Contributor

gpanshu commented Feb 11, 2022

Closing as no response in 10 days. Please reopen if this is still an issue.

@gpanshu gpanshu closed this as completed Feb 11, 2022
@sagar-docterz
Copy link

Process: com.thepediatricnetwork.receptionapp.stage, PID: 19010
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=123, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:3892 flg=0x1 }} to activity {com.thepediatricnetwork.receptionapp.stage/com.thepediatricnetwork.receptionapp.activities.AddRecordsActivity}: java.lang.IllegalArgumentException: Failed to read S3TransferUtility please check your setup or awsconfiguration.json file
at android.app.ActivityThread.deliverResults(ActivityThread.java:5590)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5631)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2336)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.IllegalArgumentException: Failed to read S3TransferUtility please check your setup or awsconfiguration.json file
at com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility$Builder.build(TransferUtility.java:292)
at com.thepediatricnetwork.receptionapp.utils.AWSUtils.uploadFileToS3(AWSUtils.kt:32)
at com.thepediatricnetwork.receptionapp.activities.AddRecordsActivity.uploadFile(AddRecordsActivity.kt:524)
at com.thepediatricnetwork.receptionapp.activities.AddRecordsActivity.onActivityResult(AddRecordsActivity.kt:401)
at android.app.Activity.dispatchActivityResult(Activity.java:8550)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5583)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5631) 
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2336) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8653) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-community-response Issue is pending response from the issue requestor question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3).
Projects
None yet
Development

No branches or pull requests

4 participants