AWS Kotlin Multiplatform v0.6.0 Help

S3

The Amazon S3 Java SDK provides a simple interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, secure, fast, inexpensive infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.

Configuration

  1. Add dependency in module shared/build.gradle.kts

    val commonMain by getting { dependencies { implementation("io.github.estivensh4:aws-s3:$lastVersion") } }
  2. Add pod in module shared/build.gradle.kts

    cocoapods { summary = "Some description for the Shared Module" homepage = "Link to the Shared Module homepage" version = "1.0" ios.deploymentTarget = "14.1" framework { baseName = "shared" } pod("AWSS3", "~> 2.33.4") // add this line }
  3. Add pod in iosApp/Podfile

    target 'iosApp' do use_frameworks! platform :ios, '14.1' pod 'shared', :path => '../shared' pod 'AWSS3', '~> 2.33.4' # add this line end

Examples

Create client

private val client = AWSS3.Builder() .accessKey("YOUR_ACCESS_KEY") .secretKey("YOUR_SECRET_KEY") .setEndpoint("YOUR_ENDPOINT") .build()

Generate Presigned URL

fun generatePresignedUrl( bucketName: String, key: String, ) { GlobalScope.launch { _generatePresignedUrl.value = client.generatePresignedUrl( bucketName = bucketName, key = key, expirationInSeconds = 3600L ) ?: "" } }
fun generatePresignedUrl( bucketName: String, key: String, ) { GlobalScope.launch { _generatePresignedUrl.value = client.generatePresignedUrl( bucketName = bucketName, key = key, expirationInSeconds = 3600L, method: HttpMethod.GET ) ?: "" } }

Create bucket

fun createBucket(bucketName: String) { GlobalScope.launch { client.createBucket(bucketName) } }

List buckets

fun listBuckets() { GlobalScope.launch { val list = client.listBuckets() } }

Delete bucket

fun deleteBucket(bucketName: String) { GlobalScope.launch { client.deleteBucket(bucketName) } }

Put object

fun putObject(bucketName: String, key: String, imageFile: ImageFile) { GlobalScope.launch { client.putObject(bucketName, key, imageFile) } }
Last modified: 28 November 2023