Download Alamofire 4 with options

I do below to load a PNG file with parameters:

Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png") // Send parameters multipartFormData.append((UserDefaults.standard.value(forKey: Email) as! String).data(using: .utf8)!, withName: "email") multipartFormData.append("png".data(using: .utf8)!, withName: "type") }, to: "user/picture", encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.responseJSON { response in debugPrint("SUCCESS RESPONSE: \(response)") } case .failure(let encodingError): self.removeSpinnerFromView() print("ERROR RESPONSE: \(encodingError)") } } ) 

The problem is that on my server I do not see the form and email form fields. I followed examples posted online for this. Is there something I have to do differently for this?

EDIT

If I remove the part that I put in:

 multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png") 

THEN options are included. Otherwise, I think this is a bug in Alamofire 4.0.1.

+13
swift3 alamofire
source share
3 answers

His work works great on my side.

I am using the following code:

 let parameters = [ "file_name": "swift_file.jpeg" ] Alamofire.upload(multipartFormData: { (multipartFormData) in multipartFormData.append(UIImageJPEGRepresentation(self.photoImageView.image!, 1)!, withName: "photo_path", fileName: "swift_file.jpeg", mimeType: "image/jpeg") for (key, value) in parameters { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } }, to:"http://sample.com/upload_img.php") { (result) in switch result { case .success(let upload, _, _): upload.uploadProgress(closure: { (progress) in //Print progress }) upload.responseJSON { response in //print response.result } case .failure(let encodingError): //print encodingError.description } } 
+38
source share

If your value is of type Any, you can change it as follows:

 for (key, value) in params { let paramsData:Data = NSKeyedArchiver.archivedData(withRootObject: value) formData.append(paramsData, withName: key) } 
+2
source share

enter image description here

Module 'Alamofire' does not have a member named 'upload'

 Alamofire.upload(multipartFormData: { (multipartFormData) in for (key, value) in param { multipartFormData.append("\(value)".data(using: String.Encoding.utf8)!, withName: key as! String) } multipartFormData.append(self.get_imagedata, withName: "image_url", fileName: "image.png", mimeType: "image/png") }, usingThreshold: UInt64.init(), to: "\(constant.Post_rating)", method: .post) { (result) in switch result{ case .success(let upload, _, _): upload.responseJSON { response in print("Succesfully uploaded = \(response)") if let err = response.error{ print(err) return } } case .failure(let error): print("Error in upload: \(error.localizedDescription)") } } } } 
0
source share

All Articles