-(void)updateUserInfo99999
{
NSString *gender = [[NSString alloc]init];
if ([self.label_sub_xb.text isEqualToString:@"男"]) {
gender = @"0";
}else{
gender = @"1";
}
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer.timeoutInterval = 20;
[manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"multipart/form-data", @"application/json", @"text/html", @"image/jpeg", @"image/jpg", @"image/png", @"application/octet-stream", @"text/json", nil];
NSDictionary *parameterDict = @{@"username":self.label_sub_nc.text,
@"phone":@"",
@"nickname":self.label_sub_nc.text,
@"gender":gender,
@"birth":self.label_sub_cs.text,
@"loginId":@"123456",
@"signature":self.label_sub_qm.text
};
NSLog(@"dicParam = %@",parameterDict);
UIImage *image = self.imageView_tx.image;
NSMutableArray *arr_image = [[NSMutableArray alloc]init];
[arr_image addObject:image];
NSLog(@"image = %@",image);
NSLog(@"arr_image = %@",arr_image);
[manager POST:[NSString stringWithFormat:@"http://192.168.0.13:808--------"] parameters:parameterDict constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
for (NSUInteger i = 0; i < arr_image.count; i++) {
// 图片经过等比压缩后得到的二进制文件
NSData *imageData = UIImageJPEGRepresentation(arr_image[i], 1.f);
// 默认图片的文件名, 若fileNames为nil就使用
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyyMMddHHmmss";
NSString *str = [formatter stringFromDate:[NSDate date]];
NSString *imageFileName = [NSString stringWithFormat:@"%@%ld.%@",str,i,@"jpg"];
NSLog(@"imageData = %@",imageData);
[formData appendPartWithFileData:imageData
name:@"file"
fileName:imageFileName
mimeType:[NSString stringWithFormat:@"image/%@",@"jpg"]];
}
} progress:^(NSProgress * _Nonnull uploadProgress) {
//上传进度
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"progress is %@",uploadProgress);
});
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"responseObject = %@",responseObject);
NSLog(@"message = %@",[responseObject valueForKey:@"message"]);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error = %@",error);
}];
}
iOS 上传图片
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 由于公司最近项目中 有个需求是要把你扫描获得的图片上传到ftp服务器 ,建于以前做的基本都是通过http 上传...