NSString *LAction=@"post_add";
NSString *urlstring=[appDelegate.SmartAutoString stringByAppendingPathComponent:[NSString stringWithFormat:@"smartautoXml.php"]];
//NSLog(@"urlstring....%@",urlstring);
NSURL *nsurl =[NSURL URLWithString:urlstring];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:nsurl];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
NSData *videoData;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *pdfPath=[documentsDir stringByAppendingFormat:@"/video.mp4"];
NSLog(@"%@",pdfPath);
if ([[NSFileManager defaultManager] fileExistsAtPath:pdfPath])
{
NSLog(@"exist");
videoData = [NSData dataWithContentsOfFile:pdfPath];
}
if (videoData)
{
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *temp=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video\"; filename=\"video.mp4\"\r\n"];
[body appendData:[[NSString stringWithString:temp] dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"temp %@",temp);
[body appendData:[@"Content-Type: video/mp4\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:videoData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}else
{
NSLog(@"NOT Data");
}
videoData=nil;
[request setHTTPBody:body];
NSLog(@"logoooooooo---q-%@",request);
NSLog(@"URLTwo Vedio==> %@?action=%@&userId=%@&postId=%@",urlstring,LAction,appDelegate.userId,stringReturnXmlOne);
con = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
if (con)
{
self.receivedData = [[NSMutableData alloc]init];
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData = data;
NSLog(@"RECIEVED DATA Video %@",self.receivedData);
}
else
{
[activityIndicator stopAnimating];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error connecting to remote server" delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
NSLog(@"Finish Video");
}