繁体   English   中英

iOS中的图片上传超时错误

[英]Image upload time out error in ios

我使用以下代码将图像上传到服务器。

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

它总是进入故障块并显示错误消息。

错误消息:错误域= NSURLErrorDomain代码= -1001“请求超时。” UserInfo = {NSErrorFailingURLStringKey = http://192.250.1.52:xxxx/api/user/profileUploadUser?userid=27&emailid=tom@gnts.in,_kCFStreamErrorCodeKey = -21022}}}

检查您的互联网速度可能很慢,

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

您可以在singleton管理一个retry counter另一件事,如果失败,则再次发出请求,如果再次失败,则显示吐司消息互联网速度很慢。

您正在尝试执行POST操作,而您想要的是file upload
试用AFNetworking分段文件上传。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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