zoukankan      html  css  js  c++  java
  • Using AFNetWorking 2.0 upload file to php web service server based on Slim

    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.

  • 相关阅读:
    CSS的z-index(分层)
    CSS的position(位置)
    HTML-答案检查&按钮倒计时
    HTML-字体逐渐显示
    2012 VS密钥
    游戏的轻度、中度、重度是什么意思
    PHP Date()函数详细参数
    服务器被黑之后的处理经历
    SEO
    ps切图步骤
  • 原文地址:https://www.cnblogs.com/shengguang/p/4870096.html
Copyright © 2011-2022 走看看