Skip to content

Instantly share code, notes, and snippets.

@maxsimych
Last active November 26, 2019 08:03
Show Gist options
  • Select an option

  • Save maxsimych/7f7a7dad3e9ab9ee5b0ac05b91b5e845 to your computer and use it in GitHub Desktop.

Select an option

Save maxsimych/7f7a7dad3e9ab9ee5b0ac05b91b5e845 to your computer and use it in GitHub Desktop.
How to store file in redux
//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