Note that there are some explanatory texts on larger screens.

plurals
  1. POAFHTTPRequestOperation fail
    primarykey
    data
    text
    <p>I am developing an app which perform following task.</p> <ol> <li>Fetch gallery images and display in grid view.</li> <li>after selecting images, they will be uploaded to server</li> </ol> <p>I use "POST" method for upload. It is working fine into iPhone simulator. But into iPhone 5 device, it will create following error after some progress of uploading.</p> <pre><code>Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1f0ba650 {NSErrorFailingURLStringKey=http://192.168.1.25/webservices/uploadphoto.php/?user_id=22, NSErrorFailingURLKey=http://192.168.1.25/webservices/uploadphoto.php/?user_id=22, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1f0a3b60 "The request timed out."} </code></pre> <p>Here, my code for uploading.</p> <pre><code> -(void)uploadImageWithStatus:(NSData *)data filenumber:(NSInteger)filenumber{ NSUserDefaults *defaultUser = [NSUserDefaults standardUserDefaults]; NSString *userId = [defaultUser stringForKey:@"UserId"]; AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",UploadURL,userId]]]; client.operationQueue.maxConcurrentOperationCount =1; //You can add POST parameteres here NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:nil]; NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:nil parameters:params constructingBodyWithBlock: ^(id &lt;AFMultipartFormData&gt;formData) { //This is the image [formData appendPartWithFileData: data name:@"f" fileName:[NSString stringWithFormat:@"%d_image.jpeg",rand()] mimeType:@"image/jpeg"]; }]; NSLog(@"Time out : %f",[request timeoutInterval]); AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { // NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite); }]; //Setup Completeion block to return successful or failure [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSString *response = [operation responseString]; NSLog(@"response: [%@]",response); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error: %@", [operation error]); if(error.code == -1001){ UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"The request timed out." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [myAlert show]; } //Code to Run if Failed }]; [operation start]; </code></pre> <p>I will be very thankful, if anyone can help me. Thanks in advanced.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload