您的位置:首页 > 移动开发 > IOS开发

ios 从系统相册选择多张图片

2015-11-24 22:34 513 查看

/article/7912228.html

http://www.xuanyusong.com/archives/1493

iOS 富文本视图控件SECoreTextView
http://www.oschina.net/p/secoretextview
https://github.com/kishikawakatsumi

版权声明:本文为博主原创文章,未经博主允许不得转载。

1.单张图片上传

name: 处为url提供的参数名

NSDictionary *dic =@{参数};
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManageralloc]
init];

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

manager.responseSerializer.acceptableContentTypes =[NSSetsetWithObject:@"text/html"];
[managerPOST:url parameters:dicconstructingBodyWithBlock:^(id<AFMultipartFormData>
formData) {

[formData appendPartWithFileData:UIImagePNGRepresentation(image)name:@"Filedata"fileName:@"test.jpg"mimeType:@"image/jpg"];
}success:^(AFHTTPRequestOperation *operation,id
responseObject) {

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

}];

2.多张图片上传

NSMutableURLRequest *request = [[AFHTTPRequestSerializer
serializer] multipartFormRequestWithMethod:@"POST"
URLString:url parameters:url参数 constructingBodyWithBlock:^(id<AFMultipartFormData>
formData) {

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

UIImage *uploadImage =
arrayImage[i];
[formData
appendPartWithFileData:UIImagePNGRepresentation(uploadImage)
name:[NSString
stringWithFormat:@"参数%d",i+1]
fileName:@"test.jpg"
mimeType:@"image/jpg"];
}
}
error:nil];

AFHTTPRequestOperation *opration = [[AFHTTPRequestOperation
alloc]initWithRequest:request];

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

[opration
setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,
id responseObject) {

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

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: