Controller/MediaController.php
public function download($id, $template = null, $templateType = 'image', CachePolicy $cachePolicy = null)
        {
            $parameters = [
            'query' => ['template' => $template, 'templateType' => $templateType],
            'body' => json_encode([], JSON_UNESCAPED_UNICODE),
            'headers' => [],
        ];

            $result = $this->get('v1/media/' . $id . '/download', $parameters, $cachePolicy);

            $tmpFile = tmpfile();
            if (false === fwrite($tmpFile, $result)) {
                throw new \RuntimeException('Could not write download data to temporary file!');
            }
            if (false === fseek($tmpFile, 0)) {
                throw new \RuntimeException('Could not reset file pointer of temporary file!');
            }
            $result = $tmpFile;

            return $result;
        }
public function download($id, $template = null, $templateType = 'image', CachePolicy $cachePolicy = null)
        {
            $parameters = [
            'query' => ['template' => $template, 'templateType' => $templateType],
            'body' => json_encode([], JSON_UNESCAPED_UNICODE),
            'headers' => [],
        ];

            $result = $this->get('v1/media/' . $id . '/download', $parameters, $cachePolicy);

            $tmpFile = tmpfile();
            if (false === fwrite($tmpFile, $result)) {
                throw new \RuntimeException('Could not write download data to temporary file!');
            }
            if (false === fseek($tmpFile, 0)) {
                throw new \RuntimeException('Could not reset file pointer of temporary file!');
            }
            $result = $tmpFile;

            return $result;
        }
Downloads a specific Media.

You may append an optional template parameter to the query. Omitting the template parameter will return the original file.

@param int         $id           the Media identifier
@param string      $template     optional template to download the media in (NOTE: This should not be used for fetching images often, use very sparingly and consider using publish-sites and templates instead)
@param string      $templateType indicates type of template, valid values are; image, video
@param CachePolicy $cachePolicy  a custom cache policy used for this request only

@return resource a file pointer resource pointing to a temporary file