對於我的客戶端,我必須爲一些不同的文件使用blob存儲。Symfony2:如何顯示/下載BLOB字段
所以我創建了一個獨立的包,其中Blob類擴展了Doctrine \ DBAL \ Types \ Type。 並在捆綁類中使用引導功能。
這工作得很好,我可以寫入數據庫Blob數據。
但我不能下載後的任何文件:/
我有:
public function downloadAction($id) {
$em = $this->getDoctrine()->getManager();
/* @var $entity Document */
$entity = $em->getRepository('Lille3SapBundle:Document')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Document entity.');
}
$file = $entity->getFichier();
$response = new \Symfony\Component\HttpFoundation\Response($file, 200, array(
'Content-Type' => 'application/octet-stream',
'Content-Length' => sizeof($file),
'Content-Disposition' => 'attachment; filename="'.$entity->getNomDocument().'"',
));
return $response;
}
和我有一個例外: 響應內容必須是一個字符串或對象實現__toString( ),給出了「資源」。
其實$文件值不是預期的BLOB但像資源ID#東西123
- >我檢查BLOB數據字段的值,和他們確定在數據庫
那麼,怎樣才能迫使我在控制器中有BLOB列而不是資源ID#111
你能告訴我們'getFichier'方法的內容嗎?在該呼叫中是否產生了「資源」?如果沒有,將資源**句柄**存儲在您的數據庫中會有點奇怪... – 2013-03-04 17:12:06