//网络提交图片信息
- (void)postWithManager:(AFHTTPRequestOperationManager *)manager url:(NSString *)url parameter:(NSDictionary *)parameter{
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
manager.requestSerializer.timeoutInterval = 20;
[manager POST:url parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:_dataImg //图片的NSData
name:@"photo"
fileName:@"ceshi.png" mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
if([responseObject[0][@"status"] isEqualToString:@"1001"]){
}else{
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
这个是单张图片发送
下面弄个多图的
- (void)postWithManager:(AFHTTPRequestOperationManager *)manager url:(NSString *)url parameter:(NSDictionary *)parameter{
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
manager.requestSerializer.timeoutInterval = 20;
[manager POST:url parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
for (int i = 0 ; i < _imgArr.count - 1; i++) {
NSData *imgData = UIImageJPEGRepresentation(_imgArr[i], 0.5);
[formData appendPartWithFileData:imgData
name:[NSString stringWithFormat:@"file%d",i + 1]
fileName:@"ceshi.png" mimeType:@"image/jpeg"];
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
if([responseObject[0][@"status"] isEqualToString:@"1001"]){
}else{
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}