extension SSNetworkManager {
func uploadingImage(imageData:Data,complete:@escaping Completion){
let url = baseURL + "/misc/update"
upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(imageData, withName: "file",fileName: "file.jpg", mimeType: "image/jpg")
}, to: url,headers: baseHeaders) { (encodingResult) in
printXY("我的:\(encodingResult)", obj: self, line: #line)
switch encodingResult {
case .success(let upload, _, _):
upload.uploadProgress { (progress) in
printXY(progress, obj: self, line: #line)
printXY(progress.fractionCompleted, obj: self, line: #line)
printXY(progress.totalUnitCount, obj: self, line: #line)
printXY(progress.completedUnitCount, obj: self, line: #line)
}.responseJSON { response in
if let jsonValue = response.result.value {
let dict:NSDictionary = jsonValue as! NSDictionary
printXY(dict, obj: self, line: #line)
let model = SSCommonModel.deserialize(from: dict)
complete(model!)
}
}
case .failure(let error):
let errorModel = SSCommonModel(error: error.localizedDescription)
complete(errorModel)
}
}
}
}
参考博客: Swift - HTTP网络操作库Alamofire使用详解2(文件上传) Swift中文件和图片上传处理 用最新的 Alamofire(swift 4.1) (带参数)post方法上传图片到服务器
|