2013-02-15 30 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

相關問題