Created
February 19, 2018 10:22
-
-
Save Bashta/87e963dd636848970091f52797322b48 to your computer and use it in GitHub Desktop.
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
func uploadDamageImage(imageData: Data, completion: @escaping UploadDamageImageCompletion) { | |
let url = "\(Config.shared.getBaseUrl())/api/images/damages" | |
print("Uploading damage image") | |
Alamofire.upload(multipartFormData: { multipartFormData in | |
multipartFormData.append(imageData, withName: "image", fileName: "dmg_image", mimeType: "image/jpg") | |
}, to: url, | |
method: .post, | |
encodingCompletion: { result in | |
switch result { | |
case .success(let upload, _, _): | |
upload.validate().responseObject { (response: DataResponse<DamageImageUploadResponse>) in | |
completion(response.result.value?.relatedEntityId, response.error) | |
} | |
case .failure(let error): | |
completion(nil, error) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment