function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
keerthana chowdharykeerthana chowdhary 

how to display the file size in salesforce

NagaNaga (Salesforce Developers) 
Hi Keerthana,


you can use the filesize attribute on the apex:inputFile to pass the filesize to a controller variable

VisualForce page
<apex:inputFile value="{!attch.body}" filename="{!nameFile}"  filesize="{!fileSize}" id="file" styleClass=""/>


Apex Class:

public Integer fileSize { get; set; }
          
if(fileSize > 5242880))
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'File is not Uploaded:Max.File Size is 5MB'));  
return null;      
}

Best regards
Naga Kiran