Skip to content
Console

Connect to S4 with the AWS SDK for Android

Add the aws-for-android framework

We strongly recommend that you never embed an AK/SK in client apps, and never deliver an AK/SK through an API.

For a better approach, see Upload files securely from the client.

Prerequisite: install the SDK (https://github.com/aws-amplify/aws-sdk-android )

s4-demo.android.java
def aws_version = '2.64.0'
implementation "com.amazonaws:aws-android-sdk-s3:$aws_version"
implementation ("com.amazonaws:aws-android-sdk-mobile-client:$aws_version")

Connect to the S4 endpoint

s4-demo.java
fun getS3Client(): AmazonS3Client {
    val credentials = object: AWSCredentials {
        override fun getAWSAccessKeyId() = accessKey // Create a sub-account in the console, then create an accessKey for it
        override fun getAWSSecretKey() = sercetKey // Important: when you create a sub-account, you must manually grant it specific permissions!
    }
    val amazonS3Client = AmazonS3Client(credentials, Region.getRegion(Regions.DEFAULT_REGION), ClientConfiguration())
    amazonS3Client.endpoint = "https://s3.bitiful.net" // Use the value shown under the "Endpoint" label at the bottom of the "Bucket settings" page in the console
    return amazonS3Client
}

List objects in a bucket

s4-demo.android.java
val s3 = getS3Client()
s3.listObjects(bucketName)

Generate a time-limited presigned download URL

s4-demo.android.java
val s3 = getS3Client()
val url = s3.generatePresignedUrl(bucketName, key, date)