Files
FBSAdminTool/src/views/Uploader/index.js

80 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-07-30 19:12:28 +05:30
import React, { useState } from 'react';
2021-07-20 22:11:32 +05:30
import axios from 'axios';
import {
2021-07-30 19:12:28 +05:30
CCol,
CFormGroup,
CInput,
CInputFile,
CLabel,
CButton,
CCard,
CCardHeader,
CCardBody,
CCardFooter,
} from '@coreui/react'
2021-07-20 22:11:32 +05:30
import CIcon from '@coreui/icons-react'
function Uploader() {
2021-07-30 19:12:28 +05:30
const [file, setFile] = useState(null);
2021-07-20 22:11:32 +05:30
2021-07-30 19:12:28 +05:30
function onChangeHandler(e) {
setFile(e.target.files[0])
}
2021-07-20 22:11:32 +05:30
2021-07-30 19:12:28 +05:30
function onClickHandler(e) {
const data = new FormData()
data.append('file', file);
//console.log(file);
2021-07-31 14:09:57 +05:30
console.log('calling upload');
2021-07-31 13:43:48 +05:30
axios.post("https://fsbsso.sumasen.net/upload", data, { // receive two parameter endpoint url ,form data
2021-07-30 19:12:28 +05:30
})
.then(res => { // then print response status
2021-08-02 15:50:55 +05:30
//console.log(res.statusText)
if (res.statusText == 'OK') {
alert("正常にアップロードされました");
}
2021-07-30 19:12:28 +05:30
});
}
2021-07-20 22:11:32 +05:30
2021-07-30 19:12:28 +05:30
return ( <
div >
<
CCard >
<
CCardHeader >
アップロード <
/CCardHeader> <
CCardBody >
<
CFormGroup row >
<
CCol md = "3" >
<
CLabel htmlFor = "date-input" > アップロードするファイルを選んでください < /CLabel> < /
CCol > <
CCol xs = "12"
md = "9" >
<
CInputFile type = "file"
onChange = { onChangeHandler }
id = "file-input"
name = "file-input" / >
<
/CCol> < /
2021-08-09 11:42:23 +05:30
CFormGroup >
<CCardFooter >
<CButton type = "submit"
2021-07-30 19:12:28 +05:30
onClick = { onClickHandler }
size = "sm"
color = "primary" > < CIcon name = "cil-scrubber" / > アップロード < /CButton> < /
2021-08-09 11:42:23 +05:30
CCardFooter>
</CCardBody>
</CCard>
</div>
2021-07-30 19:12:28 +05:30
)
2021-07-20 22:11:32 +05:30
}
2021-08-02 15:50:55 +05:30
export default Uploader