Skip to content

Instantly share code, notes, and snippets.

@korgx9
Created February 25, 2017 14:37
Show Gist options
  • Save korgx9/c83ebacf9fd0e9bc15d595ec0f624499 to your computer and use it in GitHub Desktop.
Save korgx9/c83ebacf9fd0e9bc15d595ec0f624499 to your computer and use it in GitHub Desktop.
func postImages(_ orderId: String, images: [UIImage]) {
var tmpImages = images
Alamofire.upload(multipartFormData: {
multipartFormData in
multipartFormData.append(orderId.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "order")
multipartFormData.append(UIImageJPEGRepresentation(images[0], 95)!, withName: "image", fileName: orderId + "_picture.jpg", mimeType: "image/jpg")
}, to: UserOrderUploadImageURL, encodingCompletion: {
encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON {
response in
debugPrint(response)
tmpImages.removeFirst()
if tmpImages.count > 0 {
self.postAdvertImages(orderId, images: tmpImages)
}
}
case .failure(let encodingError):
print(encodingError)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment