Created
January 21, 2017 04:12
-
-
Save ayunav/062b5562a8c8efe0f6060ee67eef22c9 to your computer and use it in GitHub Desktop.
How to upload an image using multipartFormData method with Alamofire
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // provide here the image that you want to upload, and | |
| // a value between 0 and 1 where 1 is the highest quality | |
| // https://developer.apple.com/reference/uikit/1624115-uiimagejpegrepresentation | |
| let imageData = UIImageJPEGRepresentation(image, 0.8) | |
| let url = yourUrl | |
| Alamofire.upload(multipartFormData: { multipartFormData in | |
| multipartFormData.append(imageData!, withName: "photo", fileName: "photo.jpeg", mimeType: "image/jpeg")}, | |
| to: url, | |
| encodingCompletion: { encodingResult in | |
| switch encodingResult { | |
| case .success(let upload, _, _): | |
| upload.responseJSON { response in | |
| // your implementation | |
| } | |
| case .failure(let encodingError): | |
| // your implementation | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can i ask about multiformData, how to upload more than one image data with different image parameters ??