码迷,mamicode.com
首页 > Web开发 > 详细

Using AFNetWorking 2.0 upload file to php web service server based on Slim

时间:2015-10-11 22:46:30      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

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 Slim framework, when i try to using variable $_FILES["ShopImage"] to get the image, it returns 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

标签:

原文地址:http://www.cnblogs.com/shengguang/p/4870096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!