You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
Peter Freeman edited this page Sep 1, 2019
·
1 revision
If you receive a File object via the dropzone you can read the file contents and upload it to a Web Api.
See the following example:
// in app.component.tsonFilesAdded(event){console.log(event);this.files.push(...event.addedFiles);this.readFile(this.files[0]).then(fileContents=>{// Put this string in a request body to upload it to an API.console.log(fileContents);}}privateasyncreadFile(file: File): Promise<string|ArrayBuffer>{returnnew Promise<string|ArrayBuffer>((resolve,reject)=>{constreader=newFileReader();reader.onload=e=>{returnresolve((e.targetasFileReader).result);};reader.onerror=e=>{console.error(`FileReader failed on file ${file.name}.`);returnreject(null);};if(!file){console.error('No file to read.');returnreject(null);}reader.readAsDataURL(file);});}