Skip to content

Instantly share code, notes, and snippets.

@ayunav
Created January 21, 2017 04:12
Show Gist options
  • Select an option

  • Save ayunav/062b5562a8c8efe0f6060ee67eef22c9 to your computer and use it in GitHub Desktop.

Select an option

Save ayunav/062b5562a8c8efe0f6060ee67eef22c9 to your computer and use it in GitHub Desktop.
How to upload an image using multipartFormData method with Alamofire
// 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
}
})
@jerrypm
Copy link

jerrypm commented May 14, 2018

can i ask about multiformData, how to upload more than one image data with different image parameters ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment