Using afnetworking 2.0 upload file to PHP Web service server based on Slim

Source: Internet
Author: User

Recently I am developing the IOS app, a feature is needed to upload image to the WebService server. I am using the afnetworking library. The function is as follow.

-(void) Sendimage: (NSData *) Imgdata {

Nsdictionary *parameters = @{@ "Shopid": [NSString stringwithformat:@ "%d", 1],

@ "ImageID": @ "0"

};

NSString *szaddress = utilitygetrequestaddress (easyq_cmd_upload_image);

Httprequestmanager.responseserializer = [Afjsonresponseserializer serializer];

[Httprequestmanager post:szaddress parameters:parameters constructingbodywithblock:^ (id<AFMultipartFormData > FormData) {

[FormData appendpartwithformdata:imgdata name:@ "Shopimage"];

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

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

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

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

}];

}

There is one thing need to be noticed. In the server side, I am using a Slim framework, when I-try to using variable $_files["Shopimage"] to get the image, it Retu RNs NULL. Finally I found I need to use $app->request->post (' shopimage ') to get the image data.

Using afnetworking 2.0 upload file to PHP Web service server based on Slim

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.