2017-02-24 1 views
0

두 개의 멀티 파트 이미지를 서버에 업로드하고 서버가이 두 이미지를 병합하고 응답으로 전체 이미지 1 개를 반환하는 함수를 작성했습니다. 멀티 파트 이미지에 대한 ALAMOFIRE 응답 이미지 데이터

내가
case .success(let upload, _, _): 
     upload.response { response in 
      debugPrint(response) 
      KVNProgress.dismiss() 
      completion(true) 
     } 

하지만이 얻을 응답

Alamofire.DefaultDataResponse(request: Optional([URL]), response: nil, data: Optional(0 bytes), error: Optional(Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x600000446450 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=[URL], NSErrorFailingURLKey=[URL], _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}), timeline: Timeline: { "Request Start Time": 509658047.051, "Initial Response Time": 509658047.386, "Request Completed Time": 509658166.018, "Serialization Completed Time": 509658166.021, "Latency": 0.335 secs, "Request Duration": 118.967 secs, "Serialization Duration": 0.003 secs, "Total Duration": 118.970 secs }, _metrics: Optional((Task Interval) <_NSConcreteDateInterval: 0x6000004223c0> (Start Date) 2017-02-24 19:40:47 +0000 + (Duration) 118.966891 seconds = (End Date) 2017-02-24 19:42:46 +0000 
(Redirect Count) 0 
(Transaction Metrics) (Request) <NSURLRequest: 0x600000016020> { URL: [URL] } 
(Response) (null) 
(Fetch Start) 2017-02-24 19:40:47 +0000 
(Domain Lookup Start) 2017-02-24 19:40:47 +0000 
(Domain Lookup End) 2017-02-24 19:40:47 +0000 
(Connect Start) 2017-02-24 19:40:47 +0000 
(Secure Connection Start) (null) 
(Secure Connection End) (null) 
(Connect End) 2017-02-24 19:40:47 +0000 
(Request Start) 2017-02-24 19:40:47 +0000 
(Request End) 2017-02-24 19:41:47 +0000 
(Response Start) 2017-02-24 19:40:47 +0000 
(Response End) (null) 
(Protocol Name) http/1.1 
(Proxy Connection) NO 
(Reused Connection) NO 
(Fetch Type) Network Load 

)) 

적절한 점점 저를 도와주세요이 encodeCompletion에서

func apiObjectInPainting(image: UIImage, maskedimage: UIImage,completion: @escaping (Bool) -> Swift.Void) { 
     if let data = UIImageJPEGRepresentation(image,1.0) { 
      let filename = getDocumentsDirectory().appendingPathComponent("image1.jpg") 
      try? data.write(to: filename) 
     } 
     if let data = UIImageJPEGRepresentation(maskedimage,1.0) { 
      let filename = getDocumentsDirectory().appendingPathComponent("image2.jpg") 
      try? data.write(to: filename) 
     } 

     let fileURL1 = getDocumentsDirectory().appendingPathComponent("image1.jpg") 
     let fileURL2 = getDocumentsDirectory().appendingPathComponent("image2.jpg") 
     NSLog("Files being stored @\(fileURL1)") 

     KVNProgress.show(withStatus: "Replacing Object") 

     Alamofire.upload(multipartFormData:{ multipartFormData in 
      multipartFormData.append(fileURL1, withName: "image") 
      multipartFormData.append(fileURL2, withName: "image") 
      multipartFormData.append("SECKEY".data(using: .utf8)!, withName: "Authorization") 
     }, 
         usingThreshold:UInt64.init(), 
         to:"[URL]", 
         method:.post, 
         encodingCompletion: { encodingResult in 
          switch encodingResult { 
          case .success(let upload, _, _): 
           upload.response { response in 
            debugPrint(response) 
            KVNProgress.dismiss() 
            completion(true) 
           } 
          case .failure(let encodingError): 
           KVNProgress.dismiss() 

           print(encodingError) 
          } 
     }) 

    } 

기능을이다 응답 a 현재 그것은 성공하지 못했습니다.

+0

이 오류가 반환 해피 "응답 시간이 초과되었습니다." 아마도 그 방법은 완료하는 데 오랜 시간이 걸리기 때문일 수 있습니다. 정적 응답을 반환하는 간단한 방법으로 테스트 할 수 있습니까? {' –

답변

0

많은 양의 데이터를 업로드하고있는 것으로 보이므로 요청 시간이 초과되었습니다. 시간 제한 간격과 그 작업 시간을 늘릴 수 있습니다. 여기

코드입니다 :

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() 
configuration.timeoutIntervalForResource = 10800 // seconds 
configuration.timeoutIntervalForRequest = 10800 // seconds 

alamoFireManager = Alamofire.Manager(configuration: configuration) 

코딩 :

+0

나는 코드 만 같은 문제,'매니저 = Alamofire.SessionManager.default manager.session.configuration.timeoutIntervalForRequest = 10800 manager.session.configuration.timeoutIntervalForResource = 10800 manager.upload (multipartFormData하게 시도 축소 된 이미지를 사용해 보았습니다. –

+0

I : –

관련 문제