我正在使用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() } }