Suyash Sadh
Suyash Sadh

Reputation: 17

can not upload more than 10 files using AFNetworking

I am developing an application. In which it is required to upload more than 100 images on server. For which ima using AFNetworking here is my code `

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

`

in NSLog i can observe complete process,

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

it means the process complets. But at server side I can get only 10 images. Please guide me.. why this happening.

Upvotes: 1

Views: 397

Answers (2)

Suyash Sadh
Suyash Sadh

Reputation: 17

It was a server problem. I had a dedicated server with two .ini files the support guy changed the value of max_file_uploads to 500. and it worked.

Upvotes: 0

Lix
Lix

Reputation: 47976

This could very possibly be a server side issue. There are some settings for PHP that have the capacity to limit the amount of data that can be transferred in a single request.

The settings are as follows -

Both can be set in the php.ini file.. The location of the specific file can be found by runing phpinfo().

Upvotes: 1

Related Questions