0

When uploading a file via the Visualforce apex:inputFile standard component, if the file size exceeds the 3Mb limit I would like to display a message to the user that the file is greater than 3Mb and cannot be uploaded into the system.
Please advise how this can be achieved on VisualForce level?

4

Just bind fileSize to an attribute:

public Integer fileSize { get; set; }
// ...
if(fileSize > 3000000) {
  // Show error
  return;
}

<apex:inputFile filesize="{!fileSize}" ... />
  • Shouldn't it be 3 * 1024 * 1024? so if(fileSize > 3145728) – caleb.breckon Mar 13 '18 at 17:06
  • @caleb.breckon I personally prefer the classic definition of kilo/mega/giga (base-2 notation), but Salesforce tends to use the IEC standard definitions (notice we have a 6000000 byte heap limit, not 6291456 bytes). It's really a matter of who's asking. – sfdcfox Mar 13 '18 at 18:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.