update for downloaded file

This commit is contained in:
2021-07-12 16:23:47 +05:30
parent f61eb30f5f
commit 32e12ced9b
14 changed files with 57 additions and 28 deletions

View File

@ -27,8 +27,12 @@ import {
CSwitch
} from '@coreui/react'
import CIcon from '@coreui/icons-react'
import Downloader from '../downloader';
const FileDownload = require('js-file-download');
function Index() {
const baseUrl = "https://natnats.mobilous.com/";
@ -64,7 +68,7 @@ function Index() {
function doGetReport(){
if(report == "" || selectedcons == ""){
alert("Please select both Construction and Report");
alert("建設とレポートの両方を選択してください");
return;
}
var url = baseUrl + "/" + report + "?construction_id=" +selectedcons+ "&construction_date="+sdate;
@ -75,10 +79,25 @@ function Index() {
}
function downloadReport(url) {
const response = axios(url).then((res) => {
FileDownload(res.data, 'report.xls');
})
console.log(response);
axios({
url: url, //your url
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.xlsx'); //or any other extension
document.body.appendChild(link);
link.click();
});
//return <Downloader iframeSrc={url} />
// const response = axios(url).then((res) => {
// FileDownload(res.data, 'report.xls');
// })
//console.log(response);
}
return (

10
src/views/downloader.js Normal file
View File

@ -0,0 +1,10 @@
import * as React from 'react';
function Downloader(props) {
return (
<div style={{display: 'none'}}>
<iframe src={props.iframeSrc} />
</div>
);
}
export default Downloader