php – 在浏览器上显示保存在gridfs中的pdf文件的预览

我正在使用gridfs在MongoDB中存储文件.当我尝试在浏览器中显示大型pdf文件时遇到问题,该文件保存在gridfs中.大文件不会显示在浏览器中,但小文件会显示.

这是服务代码

public function getIpFileByFileId() {
    $request = $this->request;
    $dm = $this->container->get('doctrine_mongodb')->getManager('patient');
    $id = $request->get('fileId');
    //get doc
    $docIpMapping = $dm->getRepository('PatientDocumentsBundle:IPDocuments')->findOneBy([
        'id' => $id
    ]);
    $base64 = (base64_encode($docIpMapping->getFile()->getBytes()));
    $response['data'] = $base64;
    $response['msg'] = 'success';
    return $response;
}

这是前端代码

Ajax(path, data).success(function (result) {
                        $("#pdfDiv").html('<iframe style="width:100%;height:500px;" src="data:application/pdf;base64,' + result.data + '"></iframe>');
                });

代码有问题吗?如何在前端显示大文件?

解决方法:

这是我的建议,没有在新标签中打开,
http://answerexpress.blogspot.com/2018/09/show-preview-of-pdf-file-saved-in.html

上一篇:在Laravel 5.3下使用Gridfs和mongo-php-library 2.2驱动程序


下一篇:php – 在MongoDB GridFS中存储图像