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