Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 1x 1x 1x 1x 1x 1x 1x 1x | import React, { useState, useRef } from "react";
import Modal from "react-bootstrap/Modal";
import Container from "react-bootstrap/Container";
import '../../index.css';
function Upload(props) {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
const requestData = new FormData();
const inputFile = useRef(null);
const handleClick = event => {
inputFile.current.click();
};
const handleChange = event => {
const fileUploaded = event.target.files[0];
requestData.append('dataset_name', fileUploaded.name.replace(/\.[^/.]+$/, ""));
requestData.append('file', fileUploaded);
const options = {
method: 'POST',
headers: {
Authorization: `Token ${localStorage.getItem('token')}`
},
body: requestData
}
delete options.headers['Content-Type'];
fetch('http://pear-backend-slempp.apps.cloudapps.unc.edu/api/v1/data/userSets/', options)
.then(res => res.json())
.then(data => {
console.log(data);
});
};
return (
<div>
<button type='submit' onClick={handleClick} className='btn btn-create btn-block weight-light'>Upload Data as CSV</button>
<input
type="file"
ref={inputFile}
onChange={handleChange}
style={{ display: 'none' }}
/>
</div>
)
}
export default Upload
|