-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Alexey edited this page May 13, 2019
·
5 revisions
Angular library that helps convert file (from input[type=file]) to base64/arrayBuffer/text using FileReader API.
npm install --save fctrlx-angular-file-reader
- add dependency to your project
import { FctrlxAngularFileReader } from 'fctrlx-angular-file-reader';
@NgModule({
...
imports: [
...,
FctrlxAngularFileReader,
]
})
Enjoy!
<input fileToBase64 type="file" [(files)]="fileModel">
fileToBase64
fileToArrBuf
fileToText
-
files
- your model that will be converted. -
type
- directives working only with type=file. -
multiple
- if you input is multiple - you will get in response array of files, in other case it will be an object. -
filesChange
- Event that calling when you select a file(s), usage:<input fileToText type="file" [(files)]="fileModelText" (filesChange)="onTextChanges($event)">
{
name: string;//file name
size: number;//file size
type: string;//file type
base64?: string;// base64 data
text?: string;// text data
arrBuf?: any;// array buffer data
}
https://next.plnkr.co/edit/MlwNL3BKXdVtX3Xx?preview
Alexey Khamitsevich
Author: Alexey Khamitsevich