aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.67k stars 878 forks source link

Background image upload is not working #5385

Open harshil-vyas08 opened 1 month ago

harshil-vyas08 commented 1 month ago

Describe the bug

We're adding a feature to our app where customers can upload many images at once using aws-sdk. If they choose more than 20 images and start uploading them, then minimize the app, when they bring it back up after a while (X minutes), the upload might seem stuck without showing any errors. This problem is important for our next release, and we need help figuring out if there are setup mistakes or issues in our code that could be causing this.

To Reproduce https://github.com/aws-amplify/aws-sdk-ios/assets/157394622/76e568b8-2a3c-4db2-9b51-093a124df357

Observed Behavior Image uploading gets stuck.

Expected Behavior Images should be uploaded in the background mode as well. If this is not supported then at least when user moves to the foreground the expectation is to resume uploads that are stuck.

Stack Trace N/A

Code Snippet Please provide a snippet of the code causing the issue or how you are using the service that has the bug.

In AppDelegate

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
AWSS3TransferUtility.interceptApplication(
      application,
      handleEventsForBackgroundURLSession: identifier,
      completionHandler: completionHandler)
}
var transferUtility:AWSS3TransferUtility!
transferUtility = AWSS3TransferUtility.default()
let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: "com.XYZ.XYZ.backgroundTransfer")

let transferUtilityConfiguration = AWSS3TransferUtilityConfiguration()
transferUtility.configuration.allowsCellularAccess = true
transferUtilityConfiguration.isAccelerateModeEnabled = true

 AWSS3TransferUtility.register(
    with: configuration!,
    transferUtilityConfiguration: transferUtilityConfiguration,
    forKey: "transfer-utility-with-xyz”
)
transferUtility.uploadFile(
            url,
            bucket: AWS_bucketName,
            key: key,
            contentType: "image/jpeg",
            expression: expression) { task, error in
                DispatchQueue.main.async { [weak self] in
                    print(task)

                    guard let self = self else { return }
                    if error == nil {

                    } else {
                        print("error while uploading photos::\(String(describing: error))")
                        print("error while uploading photos::\(String(describing: error?.localizedDescription))")
                        completionHandler(error)
                    }
                }
            }.continueWith { task -> AnyObject? in
                if let error = task.error {
                    print(error)
                    DispatchQueue.main.async {
                        completionHandler(error)
                    }
                }
                return nil
            }

Unique Configuration If you are reporting an issue with a unique configuration or where configuration can make a difference in code execution (i.e. Cognito) please provide your configuration. Please make sure to obfuscate sensitive information from the configuration before posting.

Areas of the SDK you are using (AWSMobileClient, Cognito, Pinpoint, IoT, etc)? AWSS3TransferUtility

Screenshots If applicable, add screenshots to help explain your problem. N/A

Environment(please complete the following information):

Device Information (please complete the following information):

Additional context N/A

Relevant Console Output Not seeing any errors

Logs No logs are available

INSERT LOG MESSAGES HERE N/A

harsh62 commented 1 month ago

@harshil-vyas08 Thanks for opening the issue. Our team will investigate and provide an update. Meanwhile, would you be able to provide any of the following?

  1. The logs you see in the console when the error happens. You can enable verbose logging to the console by doing this: AWSDDLog.sharedInstance.logLevel = .verbose AWSDDLog.add(AWSDDTTYLogger.sharedInstance)

  2. The contents of your awsconfiguration.json file with sensitive information removed.

harshil-vyas08 commented 1 month ago

@harsh62 - I can't access the logs because this issue happens only when the application is installed on the real device. I can't see this issue always happening. When I connect my device to Xcode and install the app it always works. Vice versa when I remove my device from Xcode and then just recreate whole scenario which is mentioned in ticker description I can see uploading gets stuck. If you have any other ways to retrieve the logs, please share the steps so I can help you with that.

harsh62 commented 3 weeks ago

@harshil-vyas08 Thanks for providing the information, our team is still trying to recreate the issue locally.