src/Provider/FileProvider.php
protected function generateBinaryFromRequest(MediaInterface $media)
    {
        if (!$media->getContentType()) {
            throw new \RuntimeException(
                'You must provide the content type value for your media before setting the binary content'
            );
        }

        $request = $media->getBinaryContent();

        if (!$request instanceof Request) {
            throw new \RuntimeException('Expected Request in binary content');
        }

        $content = $request->getContent();

        // create unique id for media reference
        $guesser = ExtensionGuesser::getInstance();
        $extension = $guesser->guess($media->getContentType());

        if (!$extension) {
            throw new \RuntimeException(
                sprintf('Unable to guess extension for content type %s', $media->getContentType())
            );
        }

        $handle = tmpfile();
        fwrite($handle, $content);
        $file = new ApiMediaFile($handle);
        $file->setExtension($extension);
        $file->setMimetype($media->getContentType());

        $media->setBinaryContent($file);
    }
protected function generateBinaryFromRequest(MediaInterface $media)
    {
        if (!$media->getContentType()) {
            throw new \RuntimeException(
                'You must provide the content type value for your media before setting the binary content'
            );
        }

        $request = $media->getBinaryContent();

        if (!$request instanceof Request) {
            throw new \RuntimeException('Expected Request in binary content');
        }

        $content = $request->getContent();

        // create unique id for media reference
        $guesser = ExtensionGuesser::getInstance();
        $extension = $guesser->guess($media->getContentType());

        if (!$extension) {
            throw new \RuntimeException(
                sprintf('Unable to guess extension for content type %s', $media->getContentType())
            );
        }

        $handle = tmpfile();
        fwrite($handle, $content);
        $file = new ApiMediaFile($handle);
        $file->setExtension($extension);
        $file->setMimetype($media->getContentType());

        $media->setBinaryContent($file);
    }
protected function generateBinaryFromRequest ( MediaInterface $ media ) { if ( ! $ media -> getContentType ( ) ) { throw new \ RuntimeException ( 'You must provide the content type value for your media before setting the binary content' ) ; } $ request = $ media -> getBinaryContent ( ) ; if ( ! $ request instanceof Request ) { throw new \ RuntimeException ( 'Expected Request in binary content' ) ; } $ content = $ request -> getContent ( ) ; // create unique id for media reference $ guesser = ExtensionGuesser :: getInstance ( ) ; $ extension = $ guesser -> guess ( $ media -> getContentType ( ) ) ; if ( ! $ extension ) { throw new \ RuntimeException ( sprintf ( 'Unable to guess extension for content type %s' , $ media -> getContentType ( ) ) ) ; } $ handle = tmpfile ( ) ; fwrite ( $ handle , $ content ) ; $ file = new ApiMediaFile ( $ handle ) ; $ file -> setExtension ( $ extension ) ; $ file -> setMimetype ( $ media -> getContentType ( ) ) ; $ media -> setBinaryContent ( $ file ) ; }
Set media binary content according to request content.

@param MediaInterface $media
Set media binary content according to request content .