Symfony 406(不可接受)

时间:2017-03-25 03:11:12

标签: image symfony controller

我正在尝试使用控制器设置图像路径,因为我选择添加从web /目录上传的图像。

我创建了一个ServeController:



public function urlAction($filename)
	{
	    $path = "../data/uploads/admin/";

	    $response = new BinaryFileResponse($path.$filename);
        $response->headers->set('Content-Type', 'image/jpeg');
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE);

        return $response;
	   
	}




这项工作来自我的前端reactJs,但我试图在我的symfony backoffice上显示图像我有错误406不可接受

在我的树枝模板中,我正在使用{{url(' url_image',{' filename':data.filename}}}}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

public function urlAction($filename)
{
    $path = "../data/uploads/admin/";

    $response = new Response();
    $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename);
    $response->headers->set('Content-Disposition', $disposition);
    $response->headers->set('Content-Type', 'image/jpeg');
    $response->setContent(file_get_contents($path));

    return $response;
}

不确定是否会解决这个问题。请试一试。

相关问题