iOS网络请求

iOS 多图+文字上传

2016-08-30  本文已影响810人  安勒个安

多图上传

// 向服务器提交图片
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];

// 显示进度
[manager POST:urlstr parameters:[self Params] constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
    // 上传 多张图片
    for(NSInteger i = 0; i < self.imageDataArray.count; i++)
    {
        NSData * imageData = [self.imageDataArray objectAtIndex: i];
        // 上传的参数名
        NSString * Name = [NSString stringWithFormat:@"%@%zi", Image_Name, i+1];
        // 上传filename
        NSString * fileName = [NSString stringWithFormat:@"%@.jpg", Name];
        
        [formData appendPartWithFileData:imageData name:Name fileName:fileName mimeType:@"image/jpeg"];
    }
}
success:^(AFHTTPRequestOperation *operation, id responseObject)
 {

     NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
     NSLog(@"完成 %@", result);        
 }
 failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     NSLog(@"错误 %@", error.localizedDescription);
 }];
上一篇下一篇

猜你喜欢

热点阅读