【问题标题】:uploade multiple image using restkit?使用restkit上传多张图片?
【发布时间】:2016-02-18 06:08:28
【问题描述】:

我正在使用 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];
        }
        }

【问题讨论】:

  • 检查我的答案,如果您需要任何帮助,请告诉我

标签: ios restkit


【解决方案1】:

首先将所有图像数据添加到数组中。然后像这样在表单数据上创建一个循环

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"];
    }
 }];

【讨论】:

  • 我会检查并通知您,
猜你喜欢
  • 2022-01-16
  • 2017-04-08
  • 2014-03-19
  • 2011-12-10
  • 2015-02-17
  • 2016-01-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多