我正在使用Google Cloud Storage通过Go后端服务器存储媒体文件。为了显示媒体项,我将base64编码的字符串传递到我的React前端,并通过该base64编码的字符串显示它。每当上传大PDF时,浏览器似乎都将其线性化发送,因为每当我下载文件并打印出转换为字符串的字节数组时,第一部分就是:
<?php
$_payrolldate = '2019-10-15';
$pagenum = 1;
$record_limit_per_page = 24;
$sql_count = mysqli_query($db,"SELECT COUNT(*) As total_records FROM `tbl_payroll_charges` WHERE payroll_date='$_payrolldate'");
$total_records = mysqli_fetch_array($sql_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $record_limit_per_page);
for ($pagenum = 1; $pagenum <= $total_no_of_pages; $pagenum++) {
$offset = ($pagenum-1) * $record_limit_per_page;
$sqlEmp = "SELECT
tbl_payroll_charges.acctname,
tbl_payroll_charges.payroll_date,
tbl_payroll_charges.branch,
tbl_payroll_charges.date_happened,
tbl_payroll_charges.personal_charges,
tbl_payroll_charges.inventory_charges,
tbl_payroll_charges.raw_material_charges,
tbl_payroll_charges.infraction_charges,
tbl_payroll_charges.other_charges,
tbl_payroll_charges.total_charges
FROM tbl_payroll_charges
WHERE payroll_date='$_payrolldate'
order by acctname ASC
LIMIT $offset, $record_limit_per_page";
$empResult = mysqli_query($db, $sqlEmp);
$final_total = 0;
while($listemp = mysqli_fetch_array($empResult))
{
echo $listemp['acctname']."<br>";
}
}
问题是,当我将其发送到前端应用程序时,我不知道如何显示文件。我正在使用%PDF-1.7
%\E2\E3\CF\D3
367 0 obj
<</Linearized 1/L 1659143/O 369/E 318120/N 13/T 1651687/H [ 2176 995]>>endobj
html元素来显示其余的PDF,但不适用于线性化的PDF。如何显示来自base64编码字符串的这些大PDF?