iOS upload Avatar

Source: Internet
Author: User

1 ASI Post biography pictures

Nsurl *url=[nsurl urlwithstring:[baseurl stringbyappendingstring:@ "/user/post_face.php"];

Asiformdatarequest *request=[asiformdatarequest Requestwithurl:url];

request.delegate=self;

request.timeoutseconds=120;

[Email protected] "POST";

Nsuserdefaults *defaluts=[nsuserdefaults Standarduserdefaults];

NSData *data=uiimagejpegrepresentation (editedimage, 1);

[Request Setdata:data withfilename:@ "Aa.png" andcontenttype:@ "Image/png" forkey:@ "user_img"];

[Request Setpostvalue:[defaluts objectforkey:@ "token"] forkey:@ "token"];

[Request startasynchronous];

2 afnetworking Pictures

1. Uploading Images

Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manager];

Manager.requestserializer = [Afjsonrequestserializer serializer];

Manager.responseSerializer.acceptableContentTypes = [Nsset setwithobject:@ "text/html"];

Nsmutabledictionary *dic=[[nsmutabledictionary alloc] init];

[DiC setobject:@ "Membercenter" forkey:@ "M"];

[DiC setobject:@ "Uploadphoto" forkey:@ "a"];

Nsdictionary *dic = @{@ "M": @ "appraise", @ "a": @ "Doreview"};

Loading pictures

Nsarray *array = @[@ "000", @ "1"];

[Manager post:[nsstring stringwithformat:@ "http://app.sssos.cn/index.php?"] Parameters:dic constructingbodywithblock:^ (id<afmultipartformdata> formData) {

for (int i = 0; i<array.count; i++)

{

UIImage *image=[uiimage Imagenamed:[array objectatindex:i];

NSData *data = uiimagepngrepresentation (image);

[FormData appendpartwithfiledata:data name:@ "filedata[]" filename:[nsstring stringwithformat:@ "%@.png", [array OBJECTATINDEX:I]] mimetype:@ "image/png"];

}

} success:^ (Afhttprequestoperation *operation,id responseobject) {

NSLog (@ "success:%@", responseobject);

} failure:^ (Afhttprequestoperation *operation,nserror *error) {

NSLog (@ "%@", operation.responsestring);

NSLog (@ "error:%@", error);

}];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.