diff options
-rw-r--r-- | package-lock.json | 5 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/components/FileUpload/FileUpload.tsx | 4 | ||||
-rw-r--r-- | src/utils/files.ts | 15 |
4 files changed, 17 insertions, 8 deletions
diff --git a/package-lock.json b/package-lock.json index 0e86c15..6601f4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10970,11 +10970,6 @@ "tiny-warning": "^1.0.0" } }, - "react-sage": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/react-sage/-/react-sage-0.1.2.tgz", - "integrity": "sha512-tJk2SATS0Czg5a3Sae4ilvv2W0FedBuvPFKi81qgAO7cIzn5/p1EArOYcRvGzinJVFP3/4l0Uz4gF95cx3cVhg==" - }, "react-scripts": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-3.4.1.tgz", diff --git a/package.json b/package.json index 457fa4f..c749323 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "react-error-boundary": "^2.3.1", "react-icons": "^3.10.0", "react-router-dom": "^5.2.0", - "react-sage": "^0.1.2", "react-scripts": "3.4.1", "react-virtualized": "^9.21.2", "swr": "^0.3.0", diff --git a/src/components/FileUpload/FileUpload.tsx b/src/components/FileUpload/FileUpload.tsx index 6a31656..d455f62 100644 --- a/src/components/FileUpload/FileUpload.tsx +++ b/src/components/FileUpload/FileUpload.tsx @@ -1,7 +1,7 @@ import React, { useRef } from 'react'; -import { utils } from 'react-sage'; import Button from '@material-ui/core/Button'; import CloudUpload from '@material-ui/icons/CloudUpload'; +import { getLocalFileUrl } from '../../utils/files'; interface PropTypes { callback: (fileUrl: string, file: File) => void; @@ -15,7 +15,7 @@ const FileUpload: React.FC<PropTypes> = ({ callback, children }) => { const files = event.target?.files; if (files?.length) { const file = files[0]; - utils.loadFile(file).then(url => callback(url, file)); + getLocalFileUrl(file).then(url => callback(url, file)); }; }; diff --git a/src/utils/files.ts b/src/utils/files.ts new file mode 100644 index 0000000..98c342c --- /dev/null +++ b/src/utils/files.ts @@ -0,0 +1,15 @@ +export const getLocalFileUrl = (file: File): Promise<string> => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + + reader.addEventListener('load', () => { + if (typeof reader.result === 'string') resolve(reader.result); + }, false); + + reader.addEventListener('error', () => { + reject(new Error('Error reading the file')) + }, false ); + + if (file) reader.readAsDataURL(file); + }); +}; |