IOS afnetworking 上传头像-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

IOS afnetworking 上传头像

爵霸 2016-03-11 09:59:58 1650

iOS afnetworking 上传图片 类似更换头像的功能

iOS开发
分享到
取消 提交回答
全部回答(1)
  • 爵霸
    2019-07-17 18:58:28
    //上传图片
     +(void) uploadImage:(UIImage*) img
     success:(void(^)(NSString *back_url)) mysuccess
     falure:(void(^)(NSError *er)) myfalure
     {
     NSString *path = @"http://192.168.10.252/thinkphp/index.php/Home/Index/myUpload/";
     AFHTTPRequestOperationManager * manager = [AiYuInterface getManager];
     //图片转化为二进制数据
     NSData *imgData = UIImagePNGRepresentation(img);
    //POST请求
    [manager POST:path parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:imgData name:@"image" fileName:@"img.png" mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil ];
        NSString *backUrl = dict[@"url"];
        mysuccess(backUrl);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        myfalure(error);
    }];
    
    
    }
    0 0
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题