我正在使用AFNetworking將圖像發送到我的服務器。當我從圖庫中挑選圖片時,每件事情都很好。但是,當我使用相機選擇圖像時,服務器向我發送一個錯誤,表明它的圖像無效。將圖像從相機上傳到服務器時出錯AFNetworking 3.0
- 使用UIImagePickerController從相機中選取圖像。
代碼
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
[manager.requestSerializer setValue:API_KEY_VALUE forHTTPHeaderField:API_KEY];
NSMutableURLRequest * request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:URL parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData)
{
UIImage *image = nil;
for (int i=0; i < [imagesArr count]; i++)
{
image = [imagesArr objectAtIndex:i];
// image = [UIImage imageNamed:[NSString stringWithFormat:@"%d", i+1]];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
NSString * paramName = [NSString stringWithFormat:@"scrappygram_image[%d]",i];
[formData appendPartWithFileData:imageData name:paramName
fileName:[NSString stringWithFormat:@"image_%d",i]
mimeType:@"image/jpeg"];
}
} error:nil];
[[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse response, id responseObject, NSError error)
{
if (error)
{
NSLog(@"Error: %@", error.localizedDescription);
[self.delegate apiFailedWithError:error andType:type];
} else
{
NSLog(@"%@", responseObject);
[self.delegate apiSuccessWithRespoonseDictionary:responseObject andType:type];
}
}] resume];
難道通過相機上傳時完成與選項的代碼啓動以下方法
[GMSPlacesClient provideAPIKey:GMSPLACES_API_KEY];
[GMSServices provideAPIKey: GMSPLACES_API_KEY];
[[IQKeyboardManager sharedManager] setEnable:YES];
[[IQKeyboardManager sharedManager] setShouldResignOnTouchOutside:true];
[self settingsForRemoteNotifications];
[[NSUserDefaults standardUserDefaults] setValue:DEBUG_API_FAILED_ERROR_SHOW_YES forKey:DEBUG_ERROR_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
return YES;
請問您是否可以分享您的didFinishLaunching方法代碼? –
更新您的問題。 –