private function getFileFromStream($directory, $stream)
    {
        $file = \tempnam($directory, '');
        $target = \fopen($file, 'w');
        if (0 === \stream_copy_to_stream($stream, $target)) {
            throw new \RuntimeException('Failed to write stream to file');
        }
        \fclose($target);

        return \basename($file);
    }