There was the following problem, the fact is that sometimes images are not uploaded to the server. All data is correct, the image is present, the variables are arranged in the correct order, the function reports a successful upload, but the images to the server sometimes still do not reach. There are no such problems with the Retorfit library, but with Alamofire it often arises. I can not figure out yet why.

class func write_photo(params:[String:String],image:UIImage, in_position:String, completion:_ js:String, _ success:Bool -> Void, failure:_ errorMessage:String,_ failure:Bool -> Void) { let url = BaseURL + "xdb_items.write_photo" let URL = try! URLRequest(url: url, method: .post) let in_idclient = params["in_idclient"] let in_iditem = params["in_iditem"] let imgData = UIImageJPEGRepresentation(image, 0.5)! sessionManagerImage.upload(multipartFormData: { multipartFormData in multipartFormData.append((in_idclient?.data(using: String.Encoding.utf8)!)!, withName: "in_idclient") multipartFormData.append((in_iditem?.data(using: String.Encoding.utf8)!)!, withName: "in_iditem") multipartFormData.append(imgData, withName: "in_filename", fileName: "photo", mimeType: "image/png") multipartFormData.append((in_position.data(using: String.Encoding.utf8)!), withName: "in_position") }, with: URL, encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.response { response in completion("", true) } case .failure(let encodingError): print("ERROR RESPONSE: \(encodingError)") } }) } 
  • What error occurs? - Ivan Kramarchuk pm
  • None, but accidentally did debugging and the following warning appeared: couldn’t objective-class data in the process. At real iPhone device , on the in_iditem field, maybe this is the problem, but how to solve it? - Son of God
  • This is not the problem. If there are no errors, but the image sometimes does not reach the server, then the problem is on the server. - Ivan Kramarchuk
  • Then why on Android, the library Retrofit, such problems do not arise? - Son of God
  • found an error, status code 500, because of what it can occur? - Son of God

0