Ich habe eine Funktion geschrieben, die zwei mehrteilige Bilder auf den Server hochlädt und der Server diese 2 Bilder zusammenführt und 1 ganzes Bild als Antwort zurückgibt.ALAMOFIRE Antwortbilddaten für mehrteiliges Bild
Dies ist die Funktion
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)
}
})
}
In encodeCompletion I
habencase .success(let upload, _, _):
upload.response { response in
debugPrint(response)
KVNProgress.dismiss()
completion(true)
}
Aber in der Antwort, die ich erhalten,
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
))
Bitte helfen Sie mir in die richtige bekommen Antwort a Derzeit ist es nicht erfolgreich.
Der Fehler zurückgegeben wird, "Reaktion abgelaufen." Vielleicht, weil diese Methode sehr lange dauert. Können Sie mit einer einfachen Methode testen, die nur eine statische Antwort zurückgibt? –