@@ -39,8 +39,9 @@ public function streamedDirectly($stream, string $fileName, int $fileSize): Stre
3939 * Create a response that downloads the given file via a stream.
4040 * Has the option to delete the provided file once the stream is closed.
4141 */
42- public function streamedFileDirectly (string $ filePath , string $ fileName , int $ fileSize , bool $ deleteAfter = false ): StreamedResponse
42+ public function streamedFileDirectly (string $ filePath , string $ fileName , bool $ deleteAfter = false ): StreamedResponse
4343 {
44+ $ fileSize = filesize ($ filePath );
4445 $ stream = fopen ($ filePath , 'r ' );
4546
4647 if ($ deleteAfter ) {
@@ -69,7 +70,7 @@ public function streamedFileDirectly(string $filePath, string $fileName, int $fi
6970 public function streamedInline ($ stream , string $ fileName , int $ fileSize ): StreamedResponse
7071 {
7172 $ rangeStream = new RangeSupportedStream ($ stream , $ fileSize , $ this ->request );
72- $ mime = $ rangeStream ->sniffMime ();
73+ $ mime = $ rangeStream ->sniffMime (pathinfo ( $ fileName , PATHINFO_EXTENSION ) );
7374 $ headers = array_merge ($ this ->getHeaders ($ fileName , $ fileSize , $ mime ), $ rangeStream ->getResponseHeaders ());
7475
7576 return response ()->stream (
@@ -79,6 +80,22 @@ public function streamedInline($stream, string $fileName, int $fileSize): Stream
7980 );
8081 }
8182
83+ /**
84+ * Create a response that provides the given file via a stream with detected content-type.
85+ * Has the option to delete the provided file once the stream is closed.
86+ */
87+ public function streamedFileInline (string $ filePath , ?string $ fileName = null ): StreamedResponse
88+ {
89+ $ fileSize = filesize ($ filePath );
90+ $ stream = fopen ($ filePath , 'r ' );
91+
92+ if ($ fileName === null ) {
93+ $ fileName = basename ($ filePath );
94+ }
95+
96+ return $ this ->streamedInline ($ stream , $ fileName , $ fileSize );
97+ }
98+
8299 /**
83100 * Get the common headers to provide for a download response.
84101 */
0 commit comments