Last active
November 26, 2019 08:03
-
-
Save maxsimych/7f7a7dad3e9ab9ee5b0ac05b91b5e845 to your computer and use it in GitHub Desktop.
How to store file in redux
This file contains hidden or 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
| //instead of storing the File in the store I create an URL for the file and store that in the store | |
| onDrop = (filesAccepted) => { | |
| const file = filesAccepted[0]; | |
| const url = URL.createObjectURL(file); | |
| this.props.fileSelected({name: file.name, url: url}); /* this dispatches an action */ | |
| }; | |
| //then when I need the actual content I simply retrieve it like this: | |
| const blob = await fetch(file.url).then(r => r.blob()); | |
| const file = new File([blob], file.name, {lastModified: Date().now}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment