【发布时间】:2013-03-04 17:05:18
【问题描述】:
对于我的客户,我必须为一些不同的文件使用 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() 的字符串或对象,给定的“资源”。
事实上,$file 值不是预期的 BLOB,而是类似于 Resource id #123
-> 我检查了 blob 数据字段的值,它们在数据库中都可以
那么我怎样才能在控制器中强制使用 blob 行而不是 Resource id #111
【问题讨论】:
-
你能告诉我们
getFichier方法的内容吗?resource是在该调用中生成的吗?如果不是,将资源 handle 存储在数据库中有点奇怪...