Skip to content

Instantly share code, notes, and snippets.

@herzzanu
Created February 10, 2021 10:28
Show Gist options
  • Save herzzanu/e93779283be451195de00d11fce34ba9 to your computer and use it in GitHub Desktop.
Save herzzanu/e93779283be451195de00d11fce34ba9 to your computer and use it in GitHub Desktop.
Read file method
// mirage/config.js - Adding a method for reading the file
function readFile(file) {
let reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onerror = () => {
reject(new Error('There was an error reading the file!'));
};
reader.onload = () => resolve(reader.result);
reader.readAsText(file);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment