Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

file reader with promise

export const fileReader = (file: File) => {
    const reader = new FileReader();

    if(!file) return;

    return new Promise((resolve, reject) => {
        reader.onerror = () => {
            reader.abort();
            reject(new DOMException("Problem parsing input file."));
        }

        reader.readAsDataURL(file);
        reader.onload = (e) => {
            resolve(e.target?.result);
        }
    })
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: abstract data structure types 
Typescript :: google app scripts loop 
Typescript :: read/write linked lists to file 
Typescript :: Start Angular App In Localhost 
Typescript :: what is data type in data structure 
Typescript :: how to read excel spreadsheets in c++ 
Typescript :: what is the importance of testng xml file 
Typescript :: show the current time realtime in vue 
Typescript :: no corners in broder css 
Typescript :: Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. 
Typescript :: Push Type Typescript 
Typescript :: typescript readonly 
Typescript :: props tsx 
Typescript :: nest js get request response 
Typescript :: servlets meaning 
Typescript :: typescript interview questions 
Typescript :: nest js joi usage 
Typescript :: Roblox Script wait 
Typescript :: rust typedef 
Typescript :: how to get an object from array of objects in java 
Typescript :: Find more than one child node with `children` in ResizeObserver. Please use ResizeObserver.Collection instead in React/ant design [antd] 
Typescript :: how to find out the amount of ints in c++ 
Typescript :: game object attributes 
Typescript :: field sets in salesforce 
Typescript :: require illuminate/console ^8.42|^9.0 - found illuminate/console[v8.42.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require. 
Typescript :: TypeError: __cinit__() takes at least 2 positional arguments (0 given) 
Typescript :: test valeurs 2 flottants python 
Typescript :: after effects how to parent only one property 
Typescript :: Angular/RxJs When should I unsubscribe from `Subscription` 
Typescript :: running same test in different environment 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =