Here is my new code. I think this is getting closer, as the memory footprint has shrank considerably by not reading everything into memory. Problem is that I'm now not able to write to the output file, since apparently Storage::append can't work with a file handler. How can I stream the chunks into my new file?
public function store(Request $request)
{
$file = $request->file('video');
//Hash the dzuuid in md5 just to make sure we aren't storing a tampered uuid from the request
$processing_filename = md5($request->dzuuid);
Storage::putFileAs('processing', $file, $processing_filename . '.' . $request->dzchunkindex . '.chunk');
if($request->dzchunkindex == $request->dztotalchunkcount - 1) {
//Finished Uploading. Assemble file and send to transcoder
//Create an empty file for storing assembled contents
Storage::put("processing/$processing_filename", '');
for($i = 0; $i <= $request->dzchunkindex; $i++) {
Storage::append("processing/$processing_filename", fopen(storage_path() . "/app/processing/$processing_filename.$i.chunk", 'r+'));
//Delete chunk
Storage::delete("processing/$processing_filename.$i.chunk");
}
//Now move that newly assembled file to the storage/app/transcoding directory
//Storage::move("processing/$processing_filename", "transcoding/$processing_filename");
//Now create record and send new record and the temporary filename to the transcoding job
//$video = Video::create(['user_id' => '1', 'title' => 'test', 'status' => 'processing', 'description' => 'test description']);
//TranscodeVideo::dispatch($video, $processing_filename);
}
}