let address = Service().avatarUrlString()
let headers = ["authorization": "111111"]
let imgData = UIImageJPEGRepresentation(uploadImage, 0.2)!
let URL = try! URLRequest(url: address, method: .post, headers: headers)
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(imgData, withName: "avatar", fileName: "avatar.jpg", mimeType: "image/jpeg")
}, with: URL) { (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON { response in
print(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
网友评论