使用 HTTPClient 使用 RestKit 0.20 上传文件

File uploads with RestKit 0.20 using HTTPClient

我目前正在使用以下代码post到我的服务器:

[[[RKObjectManager sharedManager] HTTPClient] postPath:[NSString stringWithFormat:@"%@%@", baseURL, @"/api/v2/track-it/rack/individual"]
                                                    parameters:params
                                                       success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                                           // handle success                                                               
                                                           if([[responseObject[@"result"] lowercaseString] isEqualToString:@"success"]){
                                                               // Entry was added
                                                               UIViewController *otherVC = [[UIStoryboard storyboardWithName:@"App" bundle:nil] instantiateViewControllerWithIdentifier:@"Dashboard"];
                                                               [self presentViewController:otherVC animated:YES completion:nil];

                                                               [self alertWithTitle:@"Track It Entry" message:@"The entry was uploaded successfully"];
                                                           } else {
                                                               // Couldn't add entry
                                                               [self alertWithTitle:@"Track It Entry" message:@"An error occured. Saving entry to upload later."];
                                                           }
                                                       }
                                                       failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                                           // response code is in operation.response.statusCode
                                                           NSLog(@"ERROR");
                                                       }];

paramsNSDictionary 个值。

我如何使用它上传文件?
我在任何地方都找不到不使用托管对象的示例。

在我的一个项目中,我使用了类似的东西。希望对你有帮助。

[[[RKObjectManager sharedManager] HTTPClient] multipartFormRequestWithMethod:RKRequestMethodPOST path:@"somePath" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    NSString *fileName = @"";
    for (UIImage *file in files) {
        fileName = [NSString stringWithFormat:@"%f.jpg", [NSDate timeIntervalSinceReferenceDate]];
        [formData appendPartWithFileData:UIImageJPEGRepresentation(file, .20) name:@"file" fileName:fileName mimeType:@"image/jpeg"];
    }
}];

在 body 块上,我为图​​像设置了一个名称,并将图像表示添加到 formData。 .20 是图像质量。