1

I have an S3Service which is a singleton that manages all the S3 related uploads and downloads. When I upload the first image it works fine but if I try to upload an Image consecutively It gives me this warning and the completion block never gets called.

A background URLSession with identifier com.amazonaws.AWSS3TransferUtility.Identifier.TransferManager already exists.

This is how I upload method looks:

if let data = image.jpegData(compressionQuality: 0.5) {
        let transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: S3Service.TRANSFER_MANAGER_KEY)
        transferUtility.uploadUsingMultiPart(data: data, bucket: EnvironmentUtils.getBucketName(), key: filename, contentType: "image/jpg", expression: nil, completionHandler: { task,error in

            if let error = error {
                print(error.localizedDescription)
            } else {
                print("Image upload success")
            }
        })
}
Agent Smith
  • 2,873
  • 17
  • 32

1 Answers1

5

The call to register transfer utility AWSS3TransferUtility.register(with: serviceconfig, forKey: KEY) was causing the above issue. There are two things that should be kept in mind.

  • The AWSS3TransferUtility should be registered only once per Application session. Then we can use AWSS3TransferUtility.S3TransferUtilityForKey to get the instance wherever needed.

  • If these are for different users within the app, ( e.g. sign-up) and if we want to keep AWSS3TransferUtility separate for each user, register AWSS3TransferUtility with a different key (preferably the same key for the same user) and look up using that key.

Agent Smith
  • 2,873
  • 17
  • 32