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)") } }) }