我正在使用REST服务的restkit库。我不知道如何发送多个图像,我可以发送单个图像,我没有想法。
[LoadingView showInView:[[UIApplication sharedApplication].delegate window]];
NSString *url=@"/upload";
NSDictionary *dic=@{@"userId":[self.appUtil getDataForKey:@"USERID"]};
NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:nil method:RKRequestMethodPOST path:url parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(imgProfile.image)
name:@"file"
fileName:@"photo.png"
mimeType:@"image/png"];
}];
RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] objectRequestOperationWithRequest:request success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
NSString* userString=operation.HTTPRequestOperation.responseString;
NSLog(@"%@",userString);
NSError* error = nil;
[LoadingView removeFromView:[[UIApplication sharedApplication].delegate window]];
StatusInnner *state=[[StatusInnner alloc]initWithString:userString error:&error];
if (state!=nil) {
if ([state.status.status isEqualToString:@"200"]) {
[self.appUtil createSimpleAlertView:self title:string_title_success
message:state.status.msg];
}else{
[self.appUtil createSimpleAlertView:self title:string_title_success
message:state.status.msg];
}
}
答案 0 :(得分:0)
首先在array中添加所有的imagedata。之后在formdata上创建一个像这样的循环
NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:nil method:RKRequestMethodPOST path:url parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
for (int i=0;i<yourImagesArray.count;i++)
{
UIImage *image = [yourImagesArray objectAtIndex:i];
[formData appendPartWithFileData:UIImagePNGRepresentation(image)
name:@"file"
fileName:@"photo.png"
mimeType:@"image/png"];
}
}];