2

If I upload .exe or .twbx files then it show the alert message like you could not these type of files using angular 4 in typescript.

Revathi Vijay
  • 1,238
  • 1
  • 13
  • 25
  • Please can we see your code that does the uploading? – rmcsharry Jun 20 '18 at 12:15
  • 2
    Bear in mind that the browser is by default an insecure environment (ie. YOU do not have control over it). Therefore even if you restrict what can be uploaded, anyone can hack your code and upload whatever they like. So you still need to ensure that your server-side code only accepts what you want it to. – rmcsharry Jun 20 '18 at 12:16
  • its upload exe alse – Revathi Vijay Jun 20 '18 at 12:20
  • Possible duplicate of [Limit file format when using ?](https://stackoverflow.com/questions/4328947/limit-file-format-when-using-input-type-file) – Muhammed Albarmavi Jun 20 '18 at 12:27

2 Answers2

3

You can use following code snippet to allow required formats

<input type="file" accept=".xls,.xlsx" />

Source: Limit file format when using <input type="file">?

Muhammed Albarmavi
  • 23,240
  • 8
  • 66
  • 91
3

Please try this.It works for me.

var regexp;
var extension = fileName.substr(fileName.lastIndexOf('.'));
if ((extension.toLowerCase() == ".exe") ||
(extension.toLowerCase() == ".twbx"))
{
alert("Could not allow to upload .exe and .twbx files");
}
srikasi
  • 224
  • 1
  • 9