The following code is to send images through the operation Queue. All requests are started one after another correctly, the server response contains the name of the image file that the client should have. The problem is that in reponseObject for the success / failure block, JSON parsing is not expected, but the type NSInLineData shown in the debugger. Now I suspect that the code to create the operation from NSMutableURLRequest caused a problem. Please, help.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; NSMutableURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:podURLString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { NSError *error; BOOL success =[formData appendPartWithFileURL:imgURL name:@"images" fileName:img.path mimeType:@"image/jpg" error:nil]; if (!success) NSLog(@"appendPartWithFileURL error: %@", error);} error:nil]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Image Success: %@", [responseObject description]); NSString *imagePath = [response objectForKey:@"imageFileName"]; [self.delegate networkManager:self didSubmitDeliveryImageForImageID:imagePath]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Image Error: %@", error); NSLog(@"image error: %@", [operation.responseObject description]); NSString *imageFilePath = [operation.responseObject objectForKey:@"imageFileName"]; [self.delegate networkManager:self didFailSubmitDeliveryImageForImageID:imageFilePath]; }]; [manager.operationQueue addOperation:operation];
ios afnetworking-2
xueru
source share