我正在使用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>');
});
代码是否有任何问题?如何在前端显示大文件?
答案 0 :(得分:1)