I'm trying to upload a linear file under http in streaming mode. The idea is do this steps simultaneously, 1) Thread 1: record an audio file and store it in a temp file 2) Thread 2: Take n bytes from temp file and send it to an http server.
How can I write an http stream?, On CFHTTPStream I did not see write methods, only read :s Do I need use sockets? Thanks!!!
My actual code is
CFWriteStreamRef stream;
NSString *strUrl = @"myurl";
NSURL *url = [[[NSURL alloc] initWithString:strUrl] retain];
CFStringRef requestMethod = CFSTR("GET");
CFHTTPMessageRef message= CFHTTPMessageCreateRequest(kCFAllocatorDefault, requestMethod, (CFURLRef)url, kCFHTTPVersion1_1);
CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Content-Type"),
CFSTR("multipart/form-data"));
stream = ?? //CFReadStreamCreateForHTTPRequest(NULL, message);
CFRelease(message);
//other headers...
if (CFWriteStreamSetProperty(stream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue) == false)
{
NSLog(@"Error");
return NO;
}
//
// Open the stream
//
if (!CFWriteStreamOpen(stream))
{
CFRelease(stream);
NSLog(@"Error");
return NO;
}
CFStreamClientContext context = {0, self, NULL, NULL, NULL};
CFWriteStreamSetClient(stram, kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
RSWriteStreamCallBack,
&context);
CFWriteStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);