首页 > Web开发 > 详细

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

时间:2015-10-11 22:45:05      阅读:371      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!