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.

  • 相关阅读:
    从Prism中学习设计模式之Event Aggregator 模式
    Apache的HttpClient调用Https忽略证书校验
    SaltStack安装及API开启
    Java连接WebSocket服务忽略证书校验
    SpringBoot实现WebSocket服务
    MySQL主从复制搭建
    Matlab基础知识(持续更新中)
    FIFO基础知识
    图像常识知识
    VC调试记录(持续更新中)
  • 原文地址:https://www.cnblogs.com/shengguang/p/4870096.html
Copyright © 2011-2022 走看看