ios AfNetWoring 上传多张图片

AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];

        //设置返回的数据解析格式

        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

        //以下为上传的一些参数,根据服务器网址要求,可以有可以没有

        NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"myUid"];

        NSString *valueWWW= [NSString stringWithFormat:@"{"uid":"%@"}",uid];

        NSMutableDictionary *ssdict = [[NSMutableDictionary alloc] init];

        [ssdict setValue:valueWWW forKey:@"home"];

        

        //post方法进行图片上传

        AFHTTPRequestOperation *operation = [manager POST:@"http://public.aiweiker.com/index.php?g=App&m=HomePage&a=updateBg" parameters:ssdict constructingBodyWithBlock:^(id<</span>AFMultipartFormData> formData) {

            

            //将图片装换为二进制格式--UIImageJPEGRepresentation第一个参数为要上传的图片,第二个参数是图片压缩的倍数

//如果要上传多张图片把下面两句代码放到for循环里即可

for (int i = 0; i<</span>0; i++) {

       NSData *imageData =UIImageJPEGRepresentation(image0.1); 

[formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"anyImage_%d",i]fileName:[NSString stringWithFormat:@"anyImage_%d.jpg",i] mimeType:@"image/jpeg"];

    }           

  } success:^(AFHTTPRequestOperation *operation, id responseObject) {

            //成功的返回--进行你的操作

            NSDictionary *dict = responseObject;


  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

            //失败的返回

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请检查网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];

            [alert show];

            [alert release];

            

        }];

        //获得上传进度

        [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {

            NSLog(@"百分比:%f",totalBytesWritten*1.0/totalBytesExpectedToWrite);

 

        }];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值