Skip to content

Commit

Permalink
Fallback to application/octet-stream if we are unable to guess the …
Browse files Browse the repository at this point in the history
…content type for a multipart file upload (#568)
  • Loading branch information
GrahamCampbell authored Aug 3, 2023
1 parent c47b9eb commit ed1315d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/MultipartStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ private function createElement(string $name, StreamInterface $stream, ?string $f
// Set a default Content-Type if one was not supplied
$type = $this->getHeader($headers, 'content-type');
if (!$type && ($filename === '0' || $filename)) {
if ($type = MimeType::fromFilename($filename)) {
$headers['Content-Type'] = $type;
}
$headers['Content-Type'] = MimeType::fromFilename($filename) ?? 'application/octet-stream';
}

return [$stream, $headers];
Expand Down
6 changes: 3 additions & 3 deletions tests/MultipartStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function testSerializesFiles(): void

$f3 = Psr7\FnStream::decorate(Psr7\Utils::streamFor('bar'), [
'getMetadata' => static function (): string {
return '/foo/bar.gif';
return '/foo/bar.unknown';
},
]);

Expand Down Expand Up @@ -176,9 +176,9 @@ public function testSerializesFiles(): void
"\r\n",
"baz\r\n",
"--boundary\r\n",
"Content-Disposition: form-data; name=\"qux\"; filename=\"bar.gif\"\r\n",
"Content-Disposition: form-data; name=\"qux\"; filename=\"bar.unknown\"\r\n",
"Content-Length: 3\r\n",
"Content-Type: image/gif\r\n",
"Content-Type: application/octet-stream\r\n",
"\r\n",
"bar\r\n",
"--boundary--\r\n",
Expand Down

0 comments on commit ed1315d

Please sign in to comment.