2013-02-15 73 views
1

我正在开发一个应用程序。其中需要在服务器上上传超过100张图片。对于那些使用IMA这里AFNetworking是我的代码`无法使用AFNetworking上传超过10个文件

AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://myserver/upload_video.php"]]; 
     NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:@"saveMediaVideo", @"methodName",userID,@"user_id",[NSString stringWithFormat:@"%d",[imageArray count]],@"img_count",@"480.0000",@"img_height" , nil]; 

     NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"http://myserver/upload_video.php" parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { 
      for (int i =0; i<[imageArray count]; i++) { 
       NSData *imageToUpload = UIImageJPEGRepresentation([imageArray objectAtIndex:i], 1.0); 
      [formData appendPartWithFileData: imageToUpload name:@"media[]" fileName:[NSString stringWithFormat:@"temp_%d.jpg",i] mimeType:@"image/jpeg"]; 
      } 
     }]; 
     AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 

     [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { 
      NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite); 
     }]; 
     [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 
      NSString *response = [operation responseString]; 
      NSLog(@"response: [%@]",response); 
      [self performSelector:@selector(killHUD) withObject:@"Processing..."]; 
      CustomAlertPopUp *alert = [[CustomAlertPopUp alloc]initWithHeaderText:@"Message" detailText:@"Spin uploaded on Server." buttonTitle:@"Ok" withTag:10 forTarget:self]; 
      [alert showView:self.view]; 
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
      [self performSelector:@selector(killHUD) withObject:@"Processing..."]; 
      if([operation.response statusCode] == 403){ 
       NSLog(@"Upload Failed"); 
       return; 
      } 
      NSLog(@"error: %@", [operation error]); 
      CustomAlertPopUp *alert = [[CustomAlertPopUp alloc]initWithHeaderText:@"Error" detailText:@"Error from server, Please try again." buttonTitle:@"Ok" withTag:0 forTarget:self]; 
      [alert showView:self.view]; 
     }]; 
     [operation start]; 

`

NSLog我可以观察整个过程

2013-02-15 19:15:37.755 MyProject[5815:907] Sent 6856280 of 6871277 bytes 
2013-02-15 19:15:37.757 MyProject[5815:907] Sent 6859176 of 6871277 bytes 
2013-02-15 19:15:37.759 MyProject[5815:907] Sent 6862072 of 6871277 bytes 
2013-02-15 19:15:37.760 MyProject[5815:907] Sent 6864968 of 6871277 bytes 
2013-02-15 19:15:37.762 MyProject[5815:907] Sent 6867864 of 6871277 bytes 
2013-02-15 19:15:37.780 MyProject[5815:907] Sent 6871277 of 6871277 bytes 

这意味着过程完整地。但在服务器端,我只能获得10张图像。请指导我..为什么会发生这种情况。

+0

是的,我正在使用apache ... – 2013-02-15 14:29:04

+0

哦..没关系 - 它的PHP设置,而不是apache ...我现在打出一个答案,可能会有所帮助... – Lix 2013-02-15 14:33:00

回答

1

这可能是一个服务器端问题。有一些PHP设置可以限制可以在单个请求中传输的数据量。

的设置如下: -

两者都可以在php.ini file.进行设置。具体文件的位置可以通过运行phpinfo()找到。

+0

嘿@Lix感谢张贴回复。根据我的服务器人员所有这些设置已在服务器端完成。是否需要任何其他信息来帮助我更多地解决此问题。 – 2013-02-16 06:16:39

+0

我确定所有设置“已完成”。否则你的服务器将不会运行! :)这两个设置的值是什么?现在,您的错误信息是说该脚本没有管理上传超过+ -6.5兆字节...设置可能需要根据您上传的文件进行更改。 – Lix 2013-02-16 08:10:29

+0

在服务器端'max_file_uploads = 600 memory_limit的= 200M(大部分图像是12-15KB) 的post_max_size = 200M' – 2013-02-16 09:07:27

0

这是一个服务器问题。我有一个专用的服务器,有两个.ini文件,支持人员将max_file_uploads的值更改为500。

+0

啊......是的是的..有一个以上的' php.ini'文件可能会让人困惑:P请注意,在我的回答中,我提到你可以使用'phpinfo()'来确定哪个ini文件正在被加载。 – Lix 2013-02-18 13:53:39

+0

很高兴听到你设法解决这个问题:) – Lix 2013-02-18 13:54:24

相关问题