Last active
October 6, 2020 08:11
-
-
Save jscodelover/c44c5ced4b548bc44878a3f27b2da533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getBase64 = file => { | |
return new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.onload = () => resolve(reader.result); | |
reader.onerror = error => reject(error); | |
reader.readAsDataURL(file); | |
}); | |
}; | |
async function onChangeFile(e) { | |
if (!csvLoading) { | |
const csv = e.target.files[0]; | |
csv && handleCsvLoading(true); | |
handleCsvName(csv.name); | |
const base64 = await getBase64(csv); | |
handleCsv(base64); | |
handleCsvLoading(false); | |
} | |
} | |
/* | |
<label | |
htmlFor="csv-upload" | |
className={csvName ? 'label-value' : 'label-placeholder'} | |
> | |
{!csvName && !csvLoading | |
? 'Select File' | |
: !csvLoading | |
? csvName | |
: 'loading...'} | |
</label> | |
<input | |
type="file" | |
className="form-control" | |
id="csv-upload" | |
placeholder="Select File" | |
accept=".csv" | |
onChange={onChangeFile} | |
/> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment