对于 web api,我将 pdf 返回为:-
[EnableCors("*", "*", "*")]
[HttpGet]
public byte[] GetReportData()
{
string filePath = "D:\\Decoding.pdf";
byte[] bytes = File.ReadAllBytes(filePath);
return bytes;
}
我在我的操作和减速器中调用该方法为:-
行动:-
export function LoadReportData () {
return (dispatch) => {
dispatch({
type: REQUEST_REPORT,//defining the name of the action to identify in the reducer
});
fetch(APIPATH+'Requisition/GetReportData')//calling the service
.then((response) => response.json())
.then((report) => dispatch(receiveReport(report)));//passing the data to other actions
}
}
//this method use to pass the data coming for the lab test result to the component
export function receiveReport(report) {
return {
type:RECEIVE_REPORT,//defining the name of the action to identify in the reducer
report:report//passing the data to reducer
};
}
减速机:-
case 'RECEIVE_REPORT':
return Object.assign({}, state, {
report: action.report,
loadingReport: false,
});
case 'REQUEST_REPORT':
return Object.assign({}, state, {
loadingReport: true
});
现在,当我从 web api 传递时,报告以字节的形式出现。现在我的要求是如何在我的组件或浏览器的下一个选项卡中显示这个来自 web api 的字节数组的 pdf 文件? 注意:报告包含字节数组