How do you use regex to get the file extension? Below is the code I'm trying to do. I tried making a method to get the file extension but seems like the method I was creating isn't working. Anyone can help?
public getExtensionFile(files: FileList): void {
for(let i = 0; i < files.length; i++) {
const file = files[i]; // files names or list
let fileDisplay = [];
const fileType = /[0-9a-z]+$/.exec(file.name);
fileDisplay['type'] = file.name.split("\\.");
if(fileType != null ){
fileDisplay['file'] = file;
}
console.log(fileDisplay[files.length-1]);
}
}
this.uploadService.fetchUploadInfo(this.resourceId).subscribe(res => {
if (res) {
this.getExtensionFile(res);
this.histories = res['histories'];
const model = res['generalInfo'] && res['generalInfo']['model'];
const selectedTagIds = _.map(res['tag']['resourceTags'], 'tagId');
const selectedTagItems = _.filter(res['tag']['tags'], function (p) {
return _.includes(selectedTagIds, p.key);
});
HTML
<div class="img-box" *ngFor="let file of referenceFiles; let i = index">
<div (click)="removeFile(i)" class="trash-icon">
<img src="assets/icons/trash-alt-solid.svg" alt="">
</div>
<img [src]="file['absoluteUri'].toLowerCase()">
<div class="text">
<span>{{ file.fileStorageId }}</span>
</div>