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

AFNetWorking 上传多张图片 (文件流)

时间:2015-08-04 20:45:13      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

服务端为新浪服务器模型   (单纯文件的存储)

方法一:

//    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.191:8080" ]];
//    [manager.operationQueue cancelAllOperations];
//    AFJSONRequestSerializer *rs = [AFJSONRequestSerializer serializer];
//    manager.requestSerializer = rs;
//    UIImage *image = [UIImage imageNamed:@"icon.png"];
//    NSData *data = UIImageJPEGRepresentation(image, 1.0);
//    NSDictionary *dic = @{@"key":@"大上海"};
//    [manager POST:@"/icreate_manager/demoUpload" parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//    [formData appendPartWithFileData:data name:[NSString stringWithFormat:@"demoFile"] fileName:[NSString stringWithFormat:@"demoFileName"] mimeType:@"image/jpeg"];
//    [formData appendPartWithFileData:data name:[NSString stringWithFormat:@"demoFile"] fileName:[NSString stringWithFormat:@"demoFileName"] mimeType:@"image/jpeg"];
//} success:^(AFHTTPRequestOperation *operation, NSDictionary *statusDict) {
//    NSLog(@"success-------");
//} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//    NSLog(@"%@",error);
//}];

方法二:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/plain",nil];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSDictionary *dic = @{@"key":@"大上海"};
    [manager POST:@"http://192.168.1.191:8080/icreate_manager/demoUpload" parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
        UIImage *img = [UIImage imageNamed:@"icon.png"];
        NSData *data = UIImageJPEGRepresentation(img, 1.0);
       // NSData *data = UIImagePNGRepresentation(img);
        [formData appendPartWithFileData:data name:@"demoFile" fileName:@"demoFileName" mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, NSDictionary *statusDict) {
        NSLog(@"oookkkk=======");
        NSLog(@"%@",statusDict);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"nononono==---==");
        NSLog(@"%@",error);
    }];

 

AFNetWorking 上传多张图片 (文件流)

标签:

原文地址:http://www.cnblogs.com/dewengood/p/4702911.html

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