美文网首页
iOS使用表单/字符串上传图片

iOS使用表单/字符串上传图片

作者: THEFUTHER | 来源:发表于2016-08-05 13:34 被阅读145次
    • (void)upDateHeadIcon:(UIImage *)photo{

      //两种方式上传头像 /方式一:使用NSData数据流传图片/

    NSString *imageURl = @"";

    manager.responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"text/html"]; [manager POST:imageURl parameters:nil constructingBodyWithBlock:^(idformData) {

    [formData appendPartWithFileData:UIImageJPEGRepresentation(photo, 1.0) name:@"text" fileName:@"test.jpg" mimeType:@"image/jpg"];

    } success:^(AFHTTPRequestOperation *operation, id responseObject) {

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];

    /方式二:使用Base64字符串传图片/

    NSData *data = UIImageJPEGRepresentation(photo, 1.0);

    NSString *pictureDataString=[data base64Encoding];

    NSDictionary * dic = @{@"verbId":@"modifyUserInfo",@"deviceType":@"ios",@"userId":@"",@"photo":pictureDataString,@"mobileTel":@""};

    [manager POST:@"" parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {

    if ([[responseObject objectForKey:@"flag"] intValue] == 0) {

    }else{

    }

    }

    failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];

    }

    相关文章

      网友评论

          本文标题:iOS使用表单/字符串上传图片

          本文链接:https://www.haomeiwen.com/subject/qbdajttx.html