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

77 lines
1.7 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
console.log(res.statusText)
});
}
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> < /
CFormGroup > <
CCardFooter >
<
CButton type = "submit"
onClick = { onClickHandler }
size = "sm"
color = "primary" > < CIcon name = "cil-scrubber" / > アップロード < /CButton> < /
CCardFooter > <
/CCardBody> < /
CCard > <
/div>
)
2021-07-20 22:11:32 +05:30
}
2021-07-30 19:12:28 +05:30
export default Uploader