Hi,
I am trying this code to write m4v file. This code works fine if i am writing any txt file. But it's not work for m4v. It creates 4kb blank m4v file for me. Can someone tell wht's going wrong in this code.
- (void)viewDidLoad {
NSString *post=@"key1=val1&key2=val2";
NSData *postData= [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://192.168.1.100:85/km/nano01_4_3.m4v"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn)
{
receivedData = [[NSMutableData data] retain];
//[postData writeToFile:@"/Users/sachinuttam/desktop/php.txt" atomically:YES];
NSString *msg = [[NSString alloc] initWithFormat:@"image location 0%i",1];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"touch image value" message:msg delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil];
[msg release];
[alert show];
[alert release];
} else
{ // inform the user that the download could not be made
NSString *msg = [[NSString alloc] initWithFormat:@"image location 0%i",123];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"touch image value" message:msg delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil];
[msg release];
[alert show];
[alert release];
}
[super viewDidLoad];
}
/*- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview.
// Release anything that's not essential, such as cached data.
} */
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
NSString *aStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
NSLog(aStr);
[receivedData writeToFile:@"/Users/sachinuttam/desktop/nano01_4_3.m4v" atomically:YES];
//[[NSData dataWithContentsOfURL:myURL] writeToFile:[cachesDirectory stringByAppendingString:@"/test.mp4"] atomically:NO];
// release the connection, and the data object
[receivedData release];
}