Swift 3 Alamofire 4使用参数上传图像数组

我正在尝试使用Alamofire 4和Swift 3上传一系列图片以及一些参数。

这些参数似乎有效,因为更新已完成,但图像无法到达服务器

在邮递员中,我可以毫无问题地做到这一点:

邮差请求样本

到目前为止这是我的代码:

let parameters = [ "service_request_id" : servicesID, "status_id" : "4", ] Alamofire.upload( multipartFormData: { multipartFormData in for (key,value) in parameters { if let value = value as? String { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } } for (image) in self.imagesArray { if let imageData = UIImageJPEGRepresentation(image, 1) { multipartFormData.append(imageData, withName: "image", fileName: "image.jpeg", mimeType: "image/jpeg") } } }, to: ConnectionWS.UpdateServicesURL, method: .put, encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.uploadProgress(closure: { (progress) in print(progress) }) upload.responseJSON { response in // If the request to get activities is succesfull, store them if response.result.isSuccess{ print(response.debugDescription) alert.dismiss(animated: true, completion: { self.dismiss(animated: true, completion: { self.delegate?.statusChanged(IsFinish: false) }) }) // Else throw an error } else { var errorMessage = "ERROR MESSAGE: " if let data = response.data { // Print message let responseJSON = JSON(data: data) if let message: String = responseJSON["error"]["message"].string { if !message.isEmpty { errorMessage += message } } } print(errorMessage) //Contains General error message or specific. print(response.debugDescription) } alert.dismiss(animated: true, completion: { self.dismiss(animated: true, completion:nil) }) } case .failure(let encodingError): print("FALLE ------------") print(encodingError) } } ) 

难道我做错了什么?

请帮忙。

所以错误来自服务器端,对图像的大小限制非常小,这就是他们没有保存的原因。 我更新了JPEG图像的压缩

 if let imageData = UIImageJPEGRepresentation(image, 1) 

 if let imageData = UIImageJPEGRepresentation(image, 0.6) 

现在它工作正常。

谢谢@Sneak的链接。

 for (key,value) in parameters { if let value = value as? String { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } } for (image) in self.imagesArray { if let imageData = UIImageJPEGRepresentation(image, 1) { multipartFormData.append(imageData, withName: "image", fileName: "image.jpeg", mimeType: "image/jpeg") } } //change this code to below for (key,value) in parameters { if let value = value as? String { if value == "image" { multipartFormData.append(imageData, withName: "image", fileName: "image.jpeg", mimeType: "image/jpeg") } else { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } } }