简体   繁体   中英

Image upload time out error in ios

I use the below code to upload image to server.

NSString *url = [NSString stringWithFormat:@"http://192.250.1.52:xxx/api/user/profileUploadUser?userid=27&emailid=tom@gnts.in"];

 NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc]init];

[jsonDict setObject:ImageToUpload forKey:@"file"];

////////ImageToUpload = /var/mobile/Containers/Data/Application/89112E0B-C1D6-4408-8586-6C5B4A431713/Documents/61.png

    [manager POST:url parameters:jsonDict
         success:^(AFHTTPRequestOperation *operation, id responseObject)
     { //////success code }


         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Image upload" message:@"failure" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
             [alert show];
             NSLog(@"error message  %@",error);
             // handle failure
         }];

It always enter into the failure block and shows the error message.

error message : Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey= http://192.250.1.52:xxxx/api/user/profileUploadUser?userid=27&emailid=tom@gnts.in , _kCFStreamErrorCodeKey=-21022}}}

Check your internet speed might be slow,

[manager.requestSerializer setTimeoutInterval:30];//Set request timeout interval time & interact with backend developer for same.

One more thing you can manage one retry counter in singleton & give second request if fails & if again fails then show toast message internet speed is slow.

You are trying to a POST operation whereas what you want is a file upload .
Try out AFNetworking multipart file upload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM