//上传头像
func requestUploadHeadImg(imageData:Data)
{
let img =UIImage(named:"1.jpg")
letimageData =UIImageJPEGRepresentation(img!,0.5)
let url ="上传头像的URL"
let array = ["text/html","text/plain","text/json","application/json","text/javascript"]
let sets=NSSet(array: array)as!Set<AnyHashable>
manager.responseSerializer =AFJSONResponseSerializer()
manager.responseSerializer.acceptableContentTypes = sets
manager.requestSerializer = AFHTTPRequestSerializer()
//所有需要传递的参数都使用类似于下面token这种方法。
let tokenStr ="token=1234567"
let tokenData = tokenStr.data(using: .utf8)
manager.post(url,parameters:nil,constructingBodyWith: { (formData:AFMultipartFormData?)in
formData?.appendPart(withFileData: imageData,name:"file",fileName:"file.jpg",mimeType: "image/jpeg")
formData?.appendPart(withForm: tokenData,name:"token")
},success: { (oper,data) -> Voidin
let data =SuccessData.initData()
self.delegate?.requestUploadHeadImgSucc!(success: data)
}) { (opeation,error) -> Voidin
let data =ErrorData.initWithError(obj: error)
self.delegate?.requestUploadHeadImgFail!(error: data)
}
}