Is this a bug? : getClientMediaType()

I’m using the odan slim4 framework
With the following code fragment in an ActionClass

    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
    $uploadedFiles = $request->getUploadedFiles();
    $file = $uploadedFiles[0];
    $contentType = $file->getClientMediaType();

When the uploaded file has a Content-Type of image/png;base64 my variable $contentType contains image/png, leaving me with no way of determining that the file has been base64 encoded.

Some debugging reveals that the $_FILES array is affected in the same way…

I think image/png;base64 is just a Data-URL according to RFC2397 and not a valid Mime-Type according to RFC2045.

The encoding can be explicitly defined in the Content-Transfer-Encoding header.

Content-Type: image/png
Content-Transfer-Encoding: base64

Hi @odan
Oh - my bad. Should have done my research - I just assumed that because the payload (that I do not control) was passing it as part of the Content-Type that it was valid as a Mime-Type. I’ll get back to the authors of the client.

That does leave the question - How does one extract the Content-Transfer-Encoding header? Would it be retrieved by the Streamnterface?

$uploadedFiles = $request->getUploadedFiles();
$file = $uploadedFiles[0];
$file->getStream()->getMetadata('wrapper_data')

Update - it seems I can’t use Postman to build this payload to test this. :frowning:

You can use the getHeaderLine method: Details

$encoding = $request->getHeaderLine('content-transfer-encoding');

I think you have to manually decode the stream content from base64 to a binary string.


$uploadedFiles = $request->getUploadedFiles();
$file = $uploadedFiles[0];
$content = (string)$file->getStream();
$encoding = $request->getHeaderLine('content-transfer-encoding');

if ($encoding === 'base64') {
    $content = base64_decode($content);
}
// ...