+ Start a Discussion

To restrict uploading filetypes

How to create a not allowed list in “Custom Settings” and add values are exe, vbs, dll, bat  ( We can add more later). Implement a filter to restrict file upload types in Saleforce environment by fetching values from custom setting.

Shailesh PatilShailesh Patil

Don't know about cutom settings but you can do it on the client side using Javascript. 


<input type="file" name="FILENAME"  size="20" onchange="check_extension(this.value,"upload");"/>
<input type="submit" id="upload" name="upload" value="Attach" disabled="disabled" />


var hash = {
  'xls'  : 1,
  'xlsx' : 1,

function check_extension(filename,submitId) {
      var re = /\..+$/;
      var ext = filename.match(re);
      var submitEl = document.getElementById(submitId);
      if (hash[ext]) {
        submitEl.disabled = false;
        return true;
      } else {
        alert("Invalid filename, please select another file");
        submitEl.disabled = true;

        return false;






but javascript can be turned off, so i would prefer not to use javascript. can u suggest something?



can i make use of a trigger on an object of Custom Settings. the custom setting would cosist of a list of the resctricted filetypes?

Shailesh PatilShailesh Patil

Hey... Can you please let me know what are you using to upload the file? Can you post your code so that I can suggest/make changes.... 



Gaurav RajGaurav Raj

Am uploading files through the Attachment Object, and i just need to create a list of certain filetypes like .exe,.bat, etc. so that these files can be restricted from being uploaded. Am trying to create a trigger which wud restrict these files from being uploaded.