FileOpener in ionic

How to randomly detect the file type and open the file… where file extension can be (doc,docx,ppt,excel) etc.

for example I get json response as
{
“Description”:“someName”,
"location"http://www.servername.com//root/Downloads/Docs//campus/1/Circulars/,
“docName”:[ “file1.docx”, “file2.pdf”, “file3.jpg” ]
}

where i get description, location and docname

so i am able to dynamically construct the url and download the files…

How to randomly detect the file type and open the file… where file extension can be (doc,docx,ppt,excel) etc.

for example in ionic documentation of File Opener (https://ionicframework.com/docs/native/file-opener/)



this.fileOpener.open(‘path/to/file.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error opening file’, e));


where you already know the file type is PDF… what if i don’t know the file type… I get file name and file location as a json response, it can be a image or word or pdf file…
how to dynamically change first line in above example “this.fileOpener.open(‘path/to/file.pdf’, ‘application/pdf’)” based on the json response

please don’t mind my english… and i am a beginner so plz help me