IOS growth path-ASIFormDataRequest for image uploading

Source: Internet
Author: User

[Cpp]
? UIImage * im = [UIImage imageWithContentsOfFile: path]; // obtain the image through path
NSData * data = UIImagePNGRepresentation (im); // obtain image data
/*
There are two methods for obtaining images in ios: UIImageJPEGRepresentation and UIImagePNGRepresentation.
The data size obtained by the former is much smaller than that obtained by the latter ..
*/
NSMutableData * imageData = [NSMutableData dataWithData: data]; // The setPostBody method of ASIFormDataRequest requires the NSMutableData type
NSURL * url = [NSURL URLWithString: @ "server address"];
ASIFormDataRequest * aRequest = [[ASIFormDataRequest alloc] initWithURL: url];
[ARequest setDelegate: self]; // proxy
 
[ARequest setRequestMethod: @ "POST"];
[ARequest setPostBody: imageData];
[ARequest addRequestHeader: @ "Content-Type" value: @ "binary/octet-stream"]; // The value here must be consistent with that on the server.
 
[ARequest startAsynchronous]; // start. Asynchronous
[ARequest setDidFinishSelector: @ selector (headPortraitSuccess)]; // The headPortraitSuccess method is automatically triggered when the request succeeds.
[ARequest setDidFailSelector: @ selector (headPortraitFail)]; // if it fails, the headPortraitFail method is automatically triggered.
[ARequest release];

Related Article

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.