I am using AFNetworking 2.0. to make a post request with multipart-formdata to the server. I am trying to upload a video and an image along with 3 string parameters.
This is working fine with POSTMAN client but not inside the app.
Here's the exact code which isn't working.
UIImage *image = img;
NSData *imageData = UIImagePNGRepresentation(image);
NSURL *urlVideo = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SampleVideo_1280x720_1mb" ofType:@"mp4"]];
NSData *videoData = [NSData dataWithContentsOfURL:urlVideo];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:requestURl]];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObjectsFromArray:@[@"application/json",@"text/html"]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:@"POST" parameters:value constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:imageData name:@"buzzymain_image" fileName:@"photo" mimeType:@"image/png"];
[formData appendPartWithFileData:videoData name:@"buzzymain" fileName:@"video" mimeType:@"video/mp4"];
[formData appendPartWithFormData:[[value valueForKey:@"buzzymain_category"] dataUsingEncoding:NSUTF8StringEncoding] name:@"buzzymain_category"];
[formData appendPartWithFormData:[[value valueForKey:@"buzzymain_title"] dataUsingEncoding:NSUTF8StringEncoding] name:@"buzzymain_title"];
[formData appendPartWithFormData:[[value valueForKey:@"buzzyuser_id"] dataUsingEncoding:NSUTF8StringEncoding] name:@"buzzyuser_id"];
} success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSString *json = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"-------\n");
NSLog(@"%@", json);
NSLog(@"-------\n");
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
{
//Something wrong
}
}];
Error with Code:
{"status":"0","message":"Please enter user Id."}
Success with POSTMAN:
{"status":"1","message":"Action Performed Successfully."}
P.S. "value" in above code is a NSDictionary.
Please suggest where I am going wrong?