2016-02-18 123 views
0

我正在使用restkit庫REST Services.I不知道如何發送多個圖像,我可以發送單個圖像,我不知道。使用restkit上傳多個圖像?

[LoadingView showInView:[[UIApplication sharedApplication].delegate window]]; 
    NSString *[email protected]"/upload"; 
    NSDictionary *[email protected]{@"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

上FORMDATA循環檢查我的答案,如果您需要任何幫助,然後讓我知道 –

回答

0

首先加入array.After所有的圖象 - 創造這樣

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

我會檢查,讓你知道, – karthikeyan