aws-sdk-ios icon indicating copy to clipboard operation
aws-sdk-ios copied to clipboard

Uploads using TransferUtility are getting stuck....

Open shrey007 opened this issue 3 years ago • 1 comments

Problem I am uploading multiple files to s3 using transferUtility. In some cases after a certain point uploads get stuck in between. In one case while uploading it got stuck at 87% and I tried waiting for around 10 mins but still it didn't continue. Any idea why this is happening?

Provide code snippets (if applicable)

func uploadBackground() {
    
    guard let transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: "transfer-utility-with-advanced-options") else {return}
    var s3UploadSucces = true
    let fileURLs = FileManager.default.listFiles(path: getRootPath()+"/"+self.folderName).filter { !$0.hasDirectoryPath }
    let numOfImages = fileURLs.count

    
    var failedUploads = [String]()
    var progress = Float(0)
    progressBar.setProgress(Float(progress), animated: true)
    progressLabel.text = String(format:"%.0f",progress*100) + "%"
    let group = DispatchGroup()

    for (index, fileURL) in fileURLs.enumerated() {
        group.enter()
        let expression = AWSS3TransferUtilityUploadExpression()
        var key = "bucket-name/" + self.folderName
        var contentType = "application/octet-stream"
        if fileURL.pathExtension == "jpg" {
            key += "/images/" + fileURL.lastPathComponent
            contentType = "image/jpeg"
        }
        else {
            key += "/" + fileURL.lastPathComponent
            contentType = "application/json"
        }
        
        expression.progressBlock = { [weak self] (task, progress) in
            DispatchQueue.main.async(execute: {
                print("Progress \(progress) \(task.key)")
                
            })
        }
        let completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock?
        completionHandler = { [weak self] (task, error) -> Void in
            DispatchQueue.main.async(execute: {

                if let error = error {
                        print("Failed with error: \(error)")
                        s3UploadSucces = false
                        failedUploads.append("Key: "+task.key)
                        failedUploads.append("Error: "+error.localizedDescription)
                                                            
                }
                else {
                    progress += 1.0/Float((numOfImages))
                    self?.progressBar.setProgress(Float(progress), animated: true)
                    self?.progressLabel.text = String(format:"%.0f",progress*100) + "%"
                    group.leave()
                }

            })
        }
        transferUtility.uploadFile(fileURL, bucket: "fashion-simulation",
                                                  key: key,
                                                  contentType: contentType,
                                                  expression: expression,
                                                  completionHandler: completionHandler)
    }
    
    group.notify(queue: DispatchQueue.global(qos: .background)) {
        print("Done..")
        
        DispatchQueue.main.async {
            if s3UploadSucces == false && progress < 1.0 {
                self.showAlert(message: failedUploads.joined(separator: " | "))
            }
            self.label.text = "Redirecting..."
            self.progressBar.isHidden = true
            self.postRequest(dir: self.folderName)
            

        }
    }
}
extension AppDelegate {
    
    func setupAWSCredentials() {
        let credentialsProvider =
        AWSCognitoCredentialsProvider(regionType:.USEast1, identityPoolId: <ID pool>)

        let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)!
         
        print(configuration.timeoutIntervalForRequest)
        print(configuration.timeoutIntervalForResource)
        let tuConf = AWSS3TransferUtilityConfiguration()
        tuConf.retryLimit = 3
        
        //Register a transfer utility object asynchronously
        AWSS3TransferUtility.register(
            with: configuration,
            transferUtilityConfiguration: tuConf,
            forKey: "transfer-utility-with-advanced-options"
        ) { (error) in
             if let error = error {
                 print("Can't register tuConf")
             }
        }
 

    }
}

Environment:

  • SDK Version: aws-sdk-ios-spm latest
  • Dependency Manager: swift package manager

Device Information:

  • Device: iPhone 11 and above (I have multiple testing devices)
  • iOS Version: iOS 15

shrey007 avatar Jun 01 '22 09:06 shrey007

Hi @shrey007, thanks for opening this issue. We’ll look into it and respond with an update here.

atierian avatar Jul 29 '22 15:07 atierian

Hi @atierian I am facing the same issue. Is there any solution we have for this?

akshaaatt avatar Nov 03 '22 08:11 akshaaatt

Hey @shrey007 and @akshaaatt, we just released AWS SDK for iOS version 2.31.1 that makes large improvements to upload speed and resolves uploads getting "stuck" in progress. For an overview of these improvements, see https://github.com/aws-amplify/amplify-swift/pull/2925.

Thanks for your patience.

atierian avatar May 03 '23 13:05 atierian