Ios Imagga.com图像重注册/内容-图像上载失败,请求超时
我试图上传图像,但失败了,这里的代码Ios Imagga.com图像重注册/内容-图像上载失败,请求超时,ios,objective-c,image-recognition,Ios,Objective C,Image Recognition,我试图上传图像,但失败了,这里的代码 AFHTTPRequestOperationManager *taggingManager = [AFHTTPRequestOperationManager manager]; [taggingManager setRequestSerializer:[AFHTTPRequestSerializer serializer]]; [taggingManager.requestSerializer setAuthorizationHeaderFieldWit
AFHTTPRequestOperationManager *taggingManager = [AFHTTPRequestOperationManager manager];
[taggingManager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[taggingManager.requestSerializer setAuthorizationHeaderFieldWithUsername: @"#" password: @"#"];
NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"apple" ofType:@"jpeg"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[taggingManager POST:@"http://api.imagga.com/v1/content"
parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imageData name:@"image"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);}];
AFHTTPRequestOperationManager*标记管理器=[AFHTTPRequestOperationManager];
[taggingManager setRequestSerializer:[AFHTTPRequestSerializer]];
[taggingManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@“#”密码:@“#”];
NSString*imagePath=[[NSBundle mainBundle]路径用于资源:@“apple”类型:@“jpeg”];
NSData*imageData=[NSData dataWithContentsOfFile:imagePath];
[标签经理职位:@”http://api.imagga.com/v1/content"
参数:nil constructingBodyWithBlock:^(id formData){
[formData appendPartWithFormData:imageData名称:@“image”];}成功:^(AFHTTPRequestOperation*操作,id响应对象){
NSLog(@“Success:%@”,responseObject);}失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“Error:%@”,Error);}];
获取此错误:error Domain=nsurerrordomain Code=-1001“请求超时。”我从imagga团队获得了帮助,效果很好
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
[manager.requestSerializer setTimeoutInterval:10]; // 10 sec. timeout for the content upload itself
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:api_key password:api_secret];
[manager POST:@"http://api.imagga.com/v1/content" parameters:nil constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFileData:imageData
name:@"file"
fileName:@"photo.jpg" mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", responseObject);
NSString *content_id = [[[responseObject valueForKey:@"uploaded"] objectAtIndex:0] valueForKey:@"id"];
NSLog(@"CONTENT ID: %@", content_id);
AFHTTPRequestOperationManager *taggingManager = [AFHTTPRequestOperationManager manager];
[taggingManager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[taggingManager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
[taggingManager.requestSerializer setTimeoutInterval:10]; // 10 sec. timeout for the tagging itself
[taggingManager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
[taggingManager.requestSerializer setAuthorizationHeaderFieldWithUsername:api_key password:api_secret];
NSLog(@"TAGGING Request for content ID: %@", content_id);
[taggingManager GET:@"http://api.imagga.com/v1/tagging" parameters:@{@"content":content_id}
success:^(AFHTTPRequestOperation *taggingOperation, id taggingResponseObject)
{
NSLog(@"TAGGING Response: %@", taggingResponseObject);
NSArray * tags = [[[taggingResponseObject valueForKey:@"results"] objectAtIndex:0] valueForKey:@"tags"];
for (id entry in tags) {
NSString *tag = [entry valueForKey:@"tag"];
float confidence = [[entry valueForKey:@"confidence"] floatValue];
// ... do something with each tag and its confidence score
}
} failure:^(AFHTTPRequestOperation *taggingOperation, NSError *taggingError) {
NSLog(@"Tagging Error: %@", taggingError);
}];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Upload Error: %@", error);
}];