iOS 上传头像


AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
sessionManager.requestSerializer.timeoutInterval = 600;
sessionManager.responseSerializer = [AFJSONResponseSerializer serializer];
[sessionManager POST:KinGuardUploadPhotoApi parameters:params constructingBodyWithBlock:^(id  _Nonnull formData) {
                // 需将image转化为NSData
           _headData = UIImageJPEGRepresentation(image, 0.5);
           [formData appendPartWithFileData: _headData name:@"HeadImage" fileName:@"KinHeadPortrait.jpg" mimeType:@"image/jpeg"];

} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
           finished(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
           failed(error.description);
}];

你可能感兴趣的:(iOS 上传头像)