【发布时间】:2017-05-21 03:43:35
【问题描述】:
对于 web api,我将 pdf 作为 :-
[EnableCors("*", "*", "*")]
[HttpGet]
public byte[] GetReportData()
{
string filePath = "D:\\Decoding.pdf";
byte[] bytes = File.ReadAllBytes(filePath);
return bytes;
}
我在 action 和 reducer 中调用该方法:-
行动:-
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 文件? 注意:报告包含字节数组
【问题讨论】:
标签: reactjs react-redux