Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 错误';请求超时';在AWSS3上并行上载文件时_Ios_Swift_Amazon S3_Timeout_Aws Sdk - Fatal编程技术网

Ios 错误';请求超时';在AWSS3上并行上载文件时

Ios 错误';请求超时';在AWSS3上并行上载文件时,ios,swift,amazon-s3,timeout,aws-sdk,Ios,Swift,Amazon S3,Timeout,Aws Sdk,我对AWSS3中的并行上载有问题 我正在使用 AWSTask(forCompletionOfAllTasks:tasks).continueWithBlock({task -> AWSTask in 在S3上并行上传文件。它可以很好地处理少量的文件,但是当我并行发送50多个文件时,我有很多超时错误,我不明白为什么 我尝试了几次并行加载150个文件,在成功上载第60个文件后,我有一个超时。大约有50个超时错误,大约需要1到2分钟,之后,上传继续,最后所有文件都成功上传,但这些超时会大大减慢

我对AWSS3中的并行上载有问题

我正在使用

AWSTask(forCompletionOfAllTasks:tasks).continueWithBlock({task -> AWSTask in
在S3上并行上传文件。它可以很好地处理少量的文件,但是当我并行发送50多个文件时,我有很多超时错误,我不明白为什么

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

我在日志中看到了错误,但我不知道如何在代码中捕获它,上载请求(AWSS3TransferManagerPloadRequest)没有返回错误,因此我无法显示错误来通知用户出现了问题

有人知道如何解决这个问题吗?如果没有解决超时问题的方法,您是否知道如何捕获错误,至少在屏幕上显示一个错误

我已经尝试更改timeoutitervalforrequest/timeoutitervalforresource,但它没有更改任何内容

错误为(五十倍或更多):

这是我的代码:

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

提前谢谢你的帮助


Stéphanie

一旦网络变慢,超时错误就会出现,因此您只需在配置中增加超时

就你而言

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

一旦网络变慢,超时错误就会出现,为此,您只需在配置中增加超时时间

就你而言

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