美文网首页
上传多张图片方法

上传多张图片方法

作者: 焉逢12 | 来源:发表于2017-02-28 13:56 被阅读0次
[SVProgressHUD showWithStatus:@"正在上传图片中.........."];

//需要传递的参数,jason格式    

NSDictionary *parameter = @{@"content":textviewStr};    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];    

manager.responseSerializer = [AFHTTPResponseSerializer serializer];    

[manager POST:[NSString stringWithFormat:@"%@/?num=1023",HostUrl] parameters:parameter constructingBodyWithBlock:^(idformData) {



for (int i = 0;i < _array.count; i++) {

UIImage *himages = [_array objectAtIndex:i];

//将图片转化成data

NSData *imageData;

if (UIImagePNGRepresentation(himages)) {

imageData = UIImageJPEGRepresentation(himages, 0.5);

} else {

imageData = UIImagePNGRepresentation(himages);

}

// 上传的参数名

NSString * Name = [NSString stringWithFormat:@"pic%d", i+1];

// 上传filename

NSString * fileName = [NSString stringWithFormat:@"%@.jpg", Name];

//                [photoNameAry addObject:fileName];

[formData appendPartWithFileData:imageData name:Name fileName:fileName mimeType:@"jpg/jpeg"];

}

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

//HStop(self);

NSLog(@"上传成功 %@", responseObject);

NSString *jsonStr = [NSString stringWithFormat:@"%@",responseObject];

if (jsonStr.length==0) {

} else {

NSData* jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];

//解析json数据,使用系统方法 JSONObjectWithData:  options: error:

NSDictionary *dddic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];

NSLog(@"praise_json==========%@",dddic);

NSString *msgStr = [NSString stringWithFormat:@"%@",dddic[@"msg"]];

NSLog(@"msgStr=======%@",msgStr);

//[HTools showTextOnlyHud:msgStr delay:1.0];

//[SVProgressHUD dismissWithDelay:1.0];

[SVProgressHUD showSuccessWithStatus:@"图片上传成功......."];

}

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

//HStop(self);

//[SVProgressHUD dismissWithDelay:1.0];

[SVProgressHUD showSuccessWithStatus:@"图片上传失败......."];

NSLog(@"error=============%@",error);

}];

相关文章

网友评论

      本文标题:上传多张图片方法

      本文链接:https://www.haomeiwen.com/subject/lwexgttx.html