小编sai*_*ist的帖子

Symfony2:如何显示/下载BLOB字段

对于我的客户端,我必须使用blob存储来处理各种文件.

所以我创建了一个带有Blob类的独立包,扩展了Doctrine\DBAL\Types\Type.并在bundle类中使用引导函数.

我可以在数据库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;
}
Run Code Online (Sandbox Code Playgroud)

我有一个例外:响应内容必须是一个字符串或对象,实现__toString(),给定"资源".

实际上,$ file值不是预期的BLOB,而是类似于资源ID#123

- >我检查了blob数据字段值,它们在数据库中没问题

那么我如何强制控制器中的blob行而不是资源ID#111

blob symfony

15
推荐指数
2
解决办法
2万
查看次数

标签 统计

blob ×1

symfony ×1