streamDownload(function () use ($hashed_path) { $stream = Storage::readStream($hashed_path); // if($stream ===false){ if ($stream === null) { throw new SystemError('Unable to read file', 500); } // Stream the file in chunks to avoid memory issues while (!feof($stream)) { $chunk = fread($stream, 8192); // 8KB chunks if ($chunk === false) { break; } echo $chunk; // Flush output buffer to ensure data is sent immediately if (ob_get_level()) { ob_flush(); } flush(); } fclose($stream); }, $filename, [ 'Content-Type' => $mime_type, 'Content-Length' => $file_size, ]); } }