Skip to content

Commit

Permalink
fix(upload): add filter to filter files with propertie accpetFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
abalad committed Feb 12, 2021
1 parent 3aae626 commit 6b5a237
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions projects/truly-ui/src/components/upload/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,33 @@ export class TlUpload implements OnInit {

onChange($event) {
if ($event.target.files.length > 0) {
const filesAccepet = this.filterFilesAccpet($event.target.files);
if (this.type === 'dragndrop') {
return this.readFiles($event.target.files);
return this.readFiles(filesAccepet);
}
const reader = new FileReader();
reader.readAsDataURL($event.target.files[0]);
reader.readAsDataURL(filesAccepet[0]);
reader.onload = (event) => {
this.imageSrc = (<FileReader>event.target).result;
this.uploadChange.emit(this.imageSrc);
};
}
}

private filterFilesAccpet( files ) {
const acceptFiles = [];
for (let i = 0; i < files.length; i++) {
const regexExpresison = this.acceptFiles
.replace( /\*/g, '.\*' )
.replace( /\,/g, '|' ) ;
const isAccept = new RegExp( regexExpresison ).test( files[ i ].type );
if ( isAccept ) {
acceptFiles.push(files[i]);
}
}
return acceptFiles;
}

private getBase64MimeType(encoded) {
let result = null;

Expand Down

0 comments on commit 6b5a237

Please sign in to comment.