amplify-swift: Why is file upload so incredibly slow?

I am uploading files that are about 300-400kb in size. The average upload time for a single file is 30 seconds which is unacceptable. How can I improve this? I’m suing the following code from your example to upload and have a fast stable wifi connection.

let dataString = "My Data"
let data = dataString.data(using: .utf8)!  
let storageOperation = Amplify.Storage.uploadData(key: "ExampleKey", data: data)
let progressSink = storageOperation.progressPublisher.sink { progress in print("Progress: \(progress)") }
let resultSink = storageOperation.resultPublisher.sink {
    if case let .failure(storageError) = $0 {
        print("Failed: \(storageError.errorDescription). \(storageError.recoverySuggestion)")
    }
}
receiveValue: { data in
    print("Completed: \(data)")
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 31 (14 by maintainers)

Most upvoted comments

@jcjimenez thank you for the code, it worked for @zachrattner and i in that we now see quicker and more reliable responses regarding progress.

Hi, we have work in progress to make this better but it has taken longer than I anticipated. However, here is a workaround you can use to speed things up:

  1. Download PresignedUrlGenerator somewhere into your application/library. This performs the subset of the work used by Amplify in order to prepare for upload.
  2. Use by entering something like the example below:
let generator = PresignedUrlGenerator(
    region: "us-east-1",
    bucket: mys3BucketName
)
let url = try await generator.presignedURL(
    for: myKey,
    accessLevel: .private
)
var request = URLRequest(url: url)
request.httpMethod = "PUT"

let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
let task = session.uploadTask(with: request,
                              fromFile: fileURL)
task.delegate = self /* You'll need to make sure to conform to URLSessionTaskDelegate*/
task.resume()

You are likely using amplifyconfig.json in your application, and if that is the case, you should be able to get the relevant region and bucket by doing something like the following:

  1. Download AmplifyConfig somewhere into your application/library.
  2. Read your amplifyconfig.json file with something like:
let amplifyConfig = try AmplifyConfig.load(from: .main)
let generator = PresignedUrlGenerator(
    region: amplifyConfig.storage.plugins.awsS3StoragePlugin.region,
    bucket: amplifyConfig.storage.plugins.awsS3StoragePlugin.bucket
)

is there any solutions for this problem , upload time is incredibly slow for me as well , 3 MB file size takes more then 8 to 9 minutes time for upload. šŸ˜”šŸ˜” + 1

I am using latest sdk and the s3 file upload is still unacceptably slow. it takes about 30 seconds to upload 400 kb.

@zachrattner I hope this workaround did the trick! For reference, it is subject to the limits posted here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html

@zachrattner the provided PresignedUrlGenerator only supports the PutObject API, but it should be more than enough for 50-100MB uploads as the API supports up to 5 GB.

is there any solutions for this problem , upload time is incredibly slow for me as well , 3 MB file size takes more then 8 to 9 minutes time for upload. šŸ˜”šŸ˜”

Just writing to update you all on progress: I do see very slow upload times (about 2 minutes for a 1.1MB file) being in Texas and uploading to AWS regions such as Mumbai. I’m taking a deeper dive to figure out if there is a root cause (in the library or SDK) apart from the physical distance.

Try a request from a different region. Such as servers in Virginia and client in Hong Kong