export function dataValidation(url) {
return axios({
url: url,
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'bearer '.concat(getAccessToken()),
},
responseType: 'blob',
});
}
// 拿到pdf的url后可以发送get请求获取文件二进制数据,responseType要设置为 'blob',
dataValidation(url).then(res => {
var blob = new Blob([res.data], {
type: 'application/pdf'
});
let qrcode = URL.createObjectURL(blob);
Modal.open({
title: 'Upload File',
fullScreen: true,
children: (
<>
<div id="pdf" style={{width:"100%",height:1000}}>
<iframe src={qrcode} style={{width:"100%",height:"100%"}} ></iframe>
</div>
</>
),
okText: 'Sure',
cancelText: 'Cancel',
onOk: () => { },
});
});
// 将拿到的二进制文件数据,res中的data创建一个blob,
// 修改blob中的type: 'application/pdf',
// URL.createObjectURL(blob);得到ifram的src,即可预览
拿到上述路径无法下载,可以使用H0中的getAttachmentUrl方法,转换后得到如下数据,此路径也可直接点击实现下载功能
import { getAttachmentUrl } from 'utils/utils';
import { getCurrentOrganizationId } from 'utils/utils';
const organizationId = getCurrentOrganizationId(); // organizationId = 0
let url = getAttachmentUrl(fileUrl, 'les', organizationId);