Skip to content

Commit 78ccf43

Browse files
committed
remove 1 stream
1 parent f157398 commit 78ccf43

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/Media/GuzzleImageDownloader.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use GuzzleHttp\Psr7\UploadedFile;
1212
use GuzzleHttp\Psr7\Utils;
1313
use Psr\Http\Client\ClientInterface;
14-
use Psr\Http\Message\StreamInterface;
1514
use Psr\Http\Message\UploadedFileInterface;
1615
use RuntimeException;
1716

@@ -74,7 +73,7 @@ public function download(Url $url): UploadedFileInterface
7473
fclose($tempStream);
7574
$stream = Utils::streamFor(fopen($tempFile, 'rb'));
7675

77-
$this->guardMimeTypeSupported($this->getFileMimeType($stream));
76+
$this->guardMimeTypeSupported($this->getFileMimeType($tempFile));
7877

7978
return new UploadedFile(
8079
$stream,
@@ -128,14 +127,12 @@ private function isInternalIp(string $ip): bool
128127
);
129128
}
130129

131-
private function getFileMimeType(StreamInterface $stream): string
130+
private function getFileMimeType(string $tempFile): string
132131
{
133-
$finfo = new \finfo();
134-
$stream->rewind();
135-
136-
/** @var string|false $mimeType */
137-
$mimeType = $finfo->buffer($stream->getContents(), FILEINFO_MIME_TYPE);
138-
return $mimeType !== false ? $mimeType : '';
132+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
133+
$mimeType = finfo_file($finfo, $tempFile);
134+
finfo_close($finfo);
135+
return $mimeType;
139136
}
140137

141138
private function guardMimeTypeSupported(string $mimeType): void

0 commit comments

Comments
 (0)