我正在使用 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>');
});
代码有问题吗?如何在前端显示大文件?
最佳答案
关于php - 在浏览器上显示保存在 gridfs 中的 pdf 文件的预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52368879/