swift soto awssdk ( s3 file ytrasfer)

40 Views Asked by At

I’m an average Swift coder, been coding 2 years. Trying for over 3 weeks to find a solution to upload an image from iPhone photo gallery to an AWS S3 bucket, Spent weeks trying to use latest AWSSDK for Swift prerelease. Got no where.

Moved onto the SOTO SDK’s, trying to get soto-s3-file-transfer to work. literally pasted code into simple View and error on final line of code awsClient.shutdown()

import SotoCore
import SotoS3


  func createBucket(bucket: String){

        let awsClient = AWSClient(
            credentialProvider: .static(accessKeyId: aws.keyaccess, secretAccessKey: aws.keysecret),
            httpClientProvider: .createNew
        )
        let s3 = S3(client: awsClient, region: .useast1)
        let createBucketRequest = S3.CreateBucketRequest(bucket: bucket)
        let createBucketFuture = s3.createBucket(createBucketRequest)
        try! awsClient.syncShutdown()
    }

original last like was awsClient.shutdown() but complier warned use try. Desperate to find support for this soto solution.

1

There are 1 best solutions below

0
On

I'm not familiar with the SOTO SDK, but if your only problem is that the syncShutdown call throws, you can rewrite it like this:

import SotoCore
import SotoS3


  func createBucket(bucket: String){

        let awsClient = AWSClient(
            credentialProvider: .static(accessKeyId: aws.keyaccess, secretAccessKey: aws.keysecret),
            httpClientProvider: .createNew
        )
        let s3 = S3(client: awsClient, region: .useast1)
        let createBucketRequest = S3.CreateBucketRequest(bucket: bucket)
        let createBucketFuture = s3.createBucket(createBucketRequest)
        do {
            try awsClient.syncShutdown()
        } catch {
            print("Error in call to awsClient.syncShutdown. Error = \(error.localizedDescription)")
            fatalError() // This causes your program to exit. Better to handle the error and recover.
        }
    }