【问题标题】:Error 'The request timed out' when uploading files in parallel on AWSS3在 AWSS3 上并行上传文件时出现错误“请求超时”
【发布时间】:2016-10-13 15:12:59
【问题描述】:

我在 AWSS3 中的并行上传有问题

我正在使用

AWSTask(forCompletionOfAllTasks:tasks).continueWithBlock({task -> AWSTask in

在 S3 上并行上传文件。它适用于少量文件,但是当我并行发送超过 50 个文件时,我有很多超时错误,我不明白为什么。

我尝试了几次并行加载 150 个文件,但在第 60 个文件成功上传后出现超时。大约有 50 个超时错误,大约需要 1 或 2 分钟,之后,上传继续,最后所有文件都成功上传,但是这些超时会大大减慢上传速度...

我在日志中看到错误,但我不知道如何在代码中捕获它,上传请求 (AWSS3TransferManagerUploadRequest) 没有返回错误,因此我无法显示错误以通知用户发生了什么事错误的。

有人知道如何解决这个问题吗?如果超时没有解决方案,你知道如何捕捉错误以至少在屏幕上显示一个错误吗?

我已经尝试更改 timeoutIntervalForRequest/timeoutIntervalForResource 但它没有改变任何东西。

错误是(五十次或更多):

20 AWSiOSSDK v2.4.8 [Error] AWSURLSessionManager.m line:212 | -[AWSURLSessionManager URLSession:task:didCompleteWithError:] | Session task failed with error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=https://s3.amazonaws.com/***/user-72358/project-***/***.jpg?partNumber=1&uploadId=***, _kCFStreamErrorCodeKey=-2102, NSErrorFailingURLKey=https://s3.amazonaws.com/***/user-***/project-***/***.jpg?partNumber=1&uploadId=***, NSLocalizedDescription=The request timed out., _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x1dc69d80 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}}

这是我的代码:

func uploadAllFileRequests(imageArray:[String], completion:(filedataReturned:FileData?, uploadOfFileSucceeded: Bool, error: NSError?)-> Void,progress:(totalSent: Int64, totalExpect: Int64)-> Void) -> Void
    {
        var tasks = [AWSTask]()

        let keyCred     = s3CredentialsInfo?.key
        AWSS3TransferManager.registerS3TransferManagerWithConfiguration(serviceConfiguration, forKey: keyCred)
        let transferManager:AWSS3TransferManager = AWSS3TransferManager.S3TransferManagerForKey(keyCred)

        for imageFilePath:String in imageArray {          
            ...

            let keyOnS3     = "\(keyCred!)/\(filename)"

            // url image to upload to s3
            let url:NSURL   = NSURL(fileURLWithPath: filedata.getFullpath())

            // next we set up the S3 upload request manager
            let uploadRequest = AWSS3TransferManagerUploadRequest()
            uploadRequest?.bucket = s3CredentialsInfo?.bucket
            uploadRequest?.key = keyOnS3 
            uploadRequest?.contentType = type 
            uploadRequest?.body = url

            // Track Upload Progress through AWSNetworkingUploadProgressBlock
            uploadRequest?.uploadProgress = {(bytesSent:Int64, totalBytesSent:Int64, totalBytesExpectedToSend:Int64) in
                dispatch_sync(dispatch_get_main_queue(), { () -> Void in
                    progress(totalSent: currentTotal, totalExpect: totalSize)
                })
            }

            tasks.append(transferManager.upload(uploadRequest).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock:{task -> AWSTask in
                if(task.result != nil){
                    // upload success
                    print("-> upload successfull \(keyOnS3) on S3")
                    completion(filedataReturned:filedata, uploadOfFileSucceeded: true, error: nil)
                }else{
                    print("->task error upload on S3 : \(task.error)")
                }
                return task
            }))
        }
        AWSTask(forCompletionOfAllTasks:tasks).continueWithBlock({task -> AWSTask in
            print("-> parallel task is \(task)")
            if(!task.cancelled && !task.faulted){
                // upload success
                print("-> upload successfull  on S3")
            }else{
                print("->error of parallel upload on S3")
                completion(filedataReturned:nil, uploadOfFileSucceeded: false, error: task.error)
            }
            return task
        })
    }

我正在使用 AWSCore 和 AWSS3 cocoapods 2.4.8 版

提前感谢您的帮助

史蒂芬妮

【问题讨论】:

    标签: ios swift amazon-s3 timeout aws-sdk


    【解决方案1】:

    一旦你的网络很慢就会出现超时错误,为此你只需要在配置中创建超时。

    你的情况

    let serviceConfiguration = AWSServiceConfiguration(region: convertedRegion, credentialsProvider: credentialsProvider)
    configuration?.timeoutIntervalForRequest = 60 // in seconds
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多