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.

  • 相关阅读:
    上传图片并压缩
    一张图教会你es6
    字符串生成二维码
    city-picker城市选择,三级联动
    jquery本地文件
    前端颜色选择器
    某音乐api
    js正则那些事
    Android判断网络是否打开,并打开设置网络界面
    execute、executeQuery和executeUpdate之间的区别 转
  • 原文地址:https://www.cnblogs.com/shengguang/p/4870096.html
Copyright © 2011-2022 走看看