Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onChange = async (e: React.ChangeEvent) => {
const file = e.currentTarget.files && e.currentTarget.files[0];
this.setState({ uploadProgress: 1 });
if (!file) {
throw Error("Looks like a file wasn't selected");
}
try {
const endpoint = await this.getUploadUrl();
const upload = createUpload({
file,
endpoint,
chunkSize: 5120, // Uploads the file in ~5mb chunks
});
upload.on('error', this.onUploadError);
upload.on('progress', this.onUploadProgress);
upload.on('success', this.onUploadSuccess);
} catch (error) {
this.setState({ error: error.message });
}
};