Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading a large video from iphone to web server
    primarykey
    data
    text
    <p>I'm trying to upload a large video from iphone to a web server that has php script.</p> <p>I'm using <code>NSInputStream</code> to get file video chunks and I'm creating a request(POST) on each traversal of the</p> <pre><code>- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode </code></pre> <p>method, with the read data passed as parameter.</p> <p>Here is the code I'm using to get chunks of data</p> <pre><code>- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode { switch(eventCode) { case NSStreamEventHasBytesAvailable: { NSMutableData *dataSlice; uint8_t buf[1048576]; unsigned int len = 0; len = [(NSInputStream *)stream read:buf maxLength:1048576]; if(len) { dataSlice = [NSMutableData dataWithBytes:(const void *)buf length:len]; NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:folderNameForUpload, kFolderName, @"abcd.MOV", kFileName, @"MOV", kFileType, nil]; MKNetworkOperation *op = [self.networkEngine operationWithPath:@"upload.php" params:params httpMethod:@"POST"]; [op addData:dataSlice forKey: @"file" mimeType: @"image/mov" fileName: @"abcd"]; [op onCompletion:^(MKNetworkOperation *completedOperation) { } onError:^(NSError *error) { }]; [[WebRequest sharedInstance].networkEngine enqueueOperation: op]; } else { NSLog(@"NO MORE BUFFER!"); } break; } case NSStreamEventEndEncountered: { [stream close]; [stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [stream release]; stream = nil; break; } } } </code></pre> <p>It is sending the data to the server, and I'm able to write the chunks into a file. But, the problem is that, if there are more than one chunk, the file will become corrupted and I'm not able to open the video file. </p> <p>I checked the file size on both server and client, and both are exactly same.</p> <p>Below is the php script, I'm using to merge video file chunks.</p> <pre><code> $tmp_file = $_FILES['file']['tmp_name']; $write_handle = fopen($fileURL, "ab+"); $read_handle = fopen($tmp_file, "rb"); $contents = fread($read_handle, filesize($tmp_file)); fwrite($write_handle, $contents); fclose($write_handle); fclose($read_handle); </code></pre> <p>What Am I doing wrong here?, Please help!</p> <p>I'm stuck over this problem!!</p> <p>Thanks in Advance,</p> <p>Suraj</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload