ios – Amazon Web Service S3超时

前端之家收集整理的这篇文章主要介绍了ios – Amazon Web Service S3超时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用S3 bucket从我的快速项目上传图像,但是,现在,我的上传暂停,并在控制台中给我以下警告.但是,我不知道为什么,但上传似乎自动重新启动,第二次几乎总是成功.并且之后的任何上传通常都很好. (只有当我没有与服务器交互一段时间
AWSiOSSDK v2.4.7 [Error] AWSURLSessionManager.m line:212 | -[AWSURLSessionManager URLSession:task:didCompleteWithError:] | Session task Failed with error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x13eba2b50 {Error Domain=kcfErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kcfStreamErrorCodeKey=-2102,_kcfStreamErrorDomainKey=4}},NSErrorFailingURLStringKey=https://s3.amazonaws.com/myBucketName/filename.jpg,NSErrorFailingURLKey=https://s3.amazonaws.com/myBucketName/filename.jpg,_kcfStreamErrorDomainKey=4,_kcfStreamErrorCodeKey=-2102,NSLocalizedDescription=The request timed out.}

下面是如何将文件发送到S3

// 2. Create upload request
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.bucket = "myBucket"
uploadRequest.key = "FileName.jpg"
uploadRequest.ACL = AWSS3ObjectCannedACL.PublicRead
uploadRequest.contentType = "image/jpg"
uploadRequest.body = url


// Track progress through an AWSNetworkingUploadProgressBlock
uploadRequest?.uploadProgress = {[weak self](bytesSent:Int64,totalBytesSent:Int64,totalBytesExpectedToSend:Int64) in
    dispatch_sync(dispatch_get_main_queue(),{ () -> Void in

        let progress = Float(totalBytesSent) / Float(totalBytesExpectedToSend)

        print(" totalBytesSent \(totalBytesSent) / totalBytesExpectedToSend \(totalBytesExpectedToSend) progress = \(progress * 100 ) %")

        circularProgressView.setProgress(progress,animated: true)

    })
}

// 3. Upload to Amazone S3
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.upload(uploadRequest).continueWithExecutor(AWSExecutor.mainThreadExecutor(),withBlock: { (task: AWSTask) -> AnyObject? in

    MRProgressOverlayView.dismissOverlayForView(self.view,animated: true)
    self.enableUserInteraction()

    if let error = task.error {

        if error.domain == AWSS3TransferUtilityErrorDomain {

            switch task.error?.code {
            case AWSS3TransferManagerErrorType.Cancelled.rawValue?:
                break
            case AWSS3TransferManagerErrorType.Paused.rawValue?:
                break
            default:
                self.showErrorAlert("Error uploading image #1",message: "\(error)")
            }
        } else {
            self.showErrorAlert("Error uploading image #2",message: "\(error)")
        }

    } else {

        if task.completed {
            let imgLink = "https://s3.amazonaws.com/letzzeeamazones3bucket2/\(uploadRequest.key!)"
            self.postToFirebase(imgLink,userCoordinate: userCoordinate)

        } else {
            self.showErrorAlert("Error uploading image #3",message: "Please try again later")
            MRProgressOverlayView.dismissOverlayForView(self.view,animated: true)
            self.enableUserInteraction()
        }
    }

解决方法

每当Amazon AWS Mobile SDK在控制台中显示不清楚的警告时,请打开详细日志记录以进行调试:

(Swift 3)
AWSLogger.default().logLevel = .verbose
(Swift 2)AWSLogger.defaultLogger().logLevel = .Verbose

…以显示有关正在使用的S3桶,区域,端点等的更多信息.

原文链接:https://www.f2er.com/iOS/335062.html

猜你在找的iOS相关文章