file reader with promise

The solution for “file reader with promise” can be found here. The following code will assist you in solving the problem.

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);
}
})
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in