这是我将多部分数据发布到服务器的代码。我观察到的是请求中只包含图像数据,而不是文章对象。如果有人在过去成功完成了这些工作,请告诉我。提前谢谢。
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromArray:@[@"title", @"author", @"body"]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping
objectClass:[Article class] rootKeyPath:@"article" method:RKRequestMethodAny];
[manager addRequestDescriptor:requestDescriptor];
Article *article = [Article new];
article.title = @"Introduction to RestKit";
article.body = @"This is some text.";
article.author = @"Blake";
NSMutableURLRequest *request = [objectManager multipartFormRequestWithObject:article
method:RKRequestMethodPOST
path:path
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData
name:imageInfo
fileName:imageName
mimeType:@"image/jpeg"];
}];
RKObjectRequestOperation *operation1 = [objectManager objectRequestOperationWithRequest:request
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
// Process data
NSLog(@"success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
// An error occurred
NSLog(@"error");
}];