Hello ,
We use the JoliCode\MediaBundle\Binary\MimeTypeGuesser class, which is constructed with:
new MimeTypeGuesser(
MimeTypesInterface $mimeTypes,
MimeTypeGuesserInterface $mimeTypeGuesser
)
On Windows the injected MimeTypeGuesserInterface resolves to Symfony\Component\Mime\FileBinaryMimeTypeGuesser, whose isGuesserSupported() returns false on Windows (because DIRECTORY_SEPARATOR === '\\') — hence the exception:
The "Symfony\Component\Mime\FileBinaryMimeTypeGuesser" guesser is not supported.
While we can work around this by injecting only MimeTypesInterface and bypassing MimeTypeGuesserInterface, it would be helpful if the bundle either:
- Detected Windows and defaulted to
MimeTypesInterface::guessMimeType() (via fileinfo) automatically, or
- Provided configuration option to disable binary-based guesser and force
fileinfo fallback, or
- Documented the Windows limitation clearly in the README.
Environnement
- OS: Windows
- PHP version: 8.2
- Symfony version: 7.4
- JoliMediaBundle version: v0.1.1
Expected
The bundle should run seamlessly on Windows by using fileinfo-based detection rather than fail with unsupported binary guesser.
Actual
Exception thrown by FileBinaryMimeTypeGuesser::guessMimeType() when used on Windows.
Suggested improvement
- Update
MimeTypeGuesser class to check isGuesserSupported() and if false fallback to $this->mimeTypes->guessMimeType().
- Add config option e.g.
joli_media.mime_type.guesser: fileinfo_only or similar.
- Add documentation note about Windows behaviour.
Working example on Windows
Replacing the bundle’s MimeTypeGuesser implementation with the following version works correctly on Windows, as it relies exclusively on MimeTypesInterface::guessMimeType() (which uses the PHP fileinfo extension):
<?php
namespace JoliCode\MediaBundle\Binary;
// use Symfony\Component\Mime\MimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypesInterface;
class MimeTypeGuesser
{
public function __construct(
private readonly MimeTypesInterface $mimeTypes,
// private readonly MimeTypeGuesserInterface $mimeTypeGuesser,
) {
}
public function getPossibleExtension(string $mimeType): string
{
$possibleExtensions = $this->mimeTypes->getExtensions($mimeType);
return $possibleExtensions[0] ?? $mimeType;
}
public function guessMimeTypeFromContent(string $content): string
{
$temporaryFile = tempnam(sys_get_temp_dir(), 'media');
file_put_contents($temporaryFile, $content);
//$mimeType = $this->mimeTypeGuesser->guessMimeType($temporaryFile);
$mimeType = $this->mimeTypes->guessMimeType($temporaryFile);
unlink($temporaryFile);
return $mimeType ?? 'application/octet-stream';
}
}
Thank
Hello ,
We use the
JoliCode\MediaBundle\Binary\MimeTypeGuesserclass, which is constructed with:On Windows the injected
MimeTypeGuesserInterfaceresolves toSymfony\Component\Mime\FileBinaryMimeTypeGuesser, whoseisGuesserSupported()returnsfalseon Windows (becauseDIRECTORY_SEPARATOR === '\\') — hence the exception:While we can work around this by injecting only
MimeTypesInterfaceand bypassingMimeTypeGuesserInterface, it would be helpful if the bundle either:MimeTypesInterface::guessMimeType()(viafileinfo) automatically, orfileinfofallback, orEnvironnement
Expected
The bundle should run seamlessly on Windows by using
fileinfo-based detection rather than fail with unsupported binary guesser.Actual
Exception thrown by
FileBinaryMimeTypeGuesser::guessMimeType()when used on Windows.Suggested improvement
MimeTypeGuesserclass to checkisGuesserSupported()and if false fallback to$this->mimeTypes->guessMimeType().joli_media.mime_type.guesser: fileinfo_onlyor similar.Working example on Windows
Replacing the bundle’s MimeTypeGuesser implementation with the following version works correctly on Windows, as it relies exclusively on MimeTypesInterface::guessMimeType() (which uses the PHP fileinfo extension):
Thank