我可以在Laravel中显示/打开/预览base64 pdf而不存储吗



目前我正在将文件存储到存储文件夹中,然后将该文件显示到浏览器中,关闭该文件后将该文件从存储中删除,但我希望直接显示到浏览器,也可以在没有存储的情况下下载。这正在工作,但正在存储文件。

$fileFromAPI = $apiResponse->file;
$bin = base64_decode($fileFromAPI, true);
$path = config('pdf_paths.file') . $id . "/";
if (!is_dir($path)) {
$oldmask = umask(0);
Storage::makeDirectory($path, 0777, true);
umask($oldmask);
}

Storage::put($path . 'file_' . $fid . '.pdf', $bin);
$pdfread = 'storage/' . $path . 'file_' . $fid . '.pdf';
return response()->file($pdfread)->deleteFileAfterSend(true);

我发现解决方案只是设置了标题并返回。

$fileFromAPI = $apiResponse->file;
$bin = base64_decode($fileFromAPI, true);
return response($bin)
->header('Content-Type', 'application/pdf');

最新更新