+ Start a Discussion
Karthikeyan ChandranKarthikeyan Chandran 

Alert on a page to upload size.

Hi Team,

I want to fix this by adding an alert message on my VF page when the upload file size is not more than 25MB. it should show the alert wherever the uploaded file is more than 25MB.

Here my vf page,
 
<apex:page sidebar="false" showheader="false" Controller="CaseController" id="Support">
<apex:form id="Page">
<apex:pageMessages />
  <html>
    <head>
        <title>My - Help</title>
        <link rel="stylesheet" href="{!URLFOR($Resource.SC_CSS,'css/index.css')}" />
        <link rel="stylesheet" href="{!URLFOR($Resource.SC_CSS,'css/grid.css')}" />
        <link rel="shortcut icon" href="{!URLFOR($Resource.SC_CSS,'css/favicon.ico')}" type="image/x-icon" />
        <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" />
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/> 
    </head>   
    <body>
        <section class="help-desk__navigation">
            <div class="container">
                <div class="table">
                    <div class="logo">
                        <img src="{!URLFOR($Resource.SC_CSS,'css/images/my-logo-black.png')}" />
                    </div>
                    <div class="cta">
                        <a class="btn">1-845-456-7888</a>
                    </div>
                </div>
            </div>
        </section>
        <section class="help-desk__header">
            <div class="container">
                <h1>Requests</h1>
            </div>
        </section>
        <section class="help-desk__sub-header">
            <div class="container">
                <ul class="help-desk__breadcrumbs">
                    <li><a href="//help.mysite.com" target="_blank">My Support Center</a></li>
                    <li>Submit a Request</li>
                </ul>
            </div>
        </section>
        <section class="help-desk__content">
            <div class="container">
                <div class="row">
                    <div class="col-md-5">
                        <h3>Submit a request</h3>
                        <div>&nbsp;</div>
                        <div class="form-field">
                            <label>Your email address<span class="required">*</span></label>                            
                            <apex:inputField id="Email" required="true" value="{!c.Email}"/>                            
                        </div>
                        <div class="form-field">
                            <label>Subject<span  class="required">*</span></label>                            
                            <apex:inputText id="Subject" required="true" value="{!strSubject }" maxlength="250" size="25" />
                        </div>
                        <div class="form-field">
                            <p>Please enter the details of your request. A member of our support staff will respond as soon as possible.</p>
                        </div>
                        <div class="form-field">
                            <label>Description<span class="required">*</span></label>                            
                            <apex:inputTextarea id="Description" required="true" value="{!strDescription}"/>
                        </div>
                       <!--<div class="form-field">
                            <label>Attachments</label>
                            <div class="upload-box text-center ripple">
                               <input type="file"  value="{!attachment.body}"  filename="{!attachment.name}" />
                                <span><img src="{!URLFOR($Resource.SC_CSS,'css/images/paperclip.png')}"  /></span>
                                <span><a>Add file</a> or drop files here</span>
                            </div>
                        </div>-->
                        <div class="form-field">
                            <label>Attachments</label>
                            <div>                                
                                <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
                            </div>
                        </div>
                        <div class="form-field text-right">
                           <a class="btn" onclick="jsCallSavefn()" >Submit</a>                         
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <section class="help-desk__footer">
            <div class="container">
                <div class="row">
                    <div class="col-md-5">
                        <div class="logo">
                            <img src="{!URLFOR($Resource.SC_CSS,'css/images/my-logo-black.png')}"   />
                        </div>
                        <p>Mysite is the all-in-one solution for local business owners &ndash; equipping them with an HTML5, mobile-responsive website and an ever-expanding product suite that gives them the power to tell their story and reinvent their digital presence.</p>
                        <p>&copy; 2017 Mysite. All rights reserved.</p>
                    </div>
                    <div class="col-md-7">
                        <div class="row">
                            <div class="col-md-6">
                                <h3>Company</h3>
                                <ul class="bordered-list">
                                    <li><a href="//www.mysite.com/" target="_blank">What is Mysite?</a></li>
                                    <li><a href="//blog.mysite.com/" target="_blank">Blog</a></li>
                                </ul>
                            </div>
                            <div class="col-md-6">
                                <h3>Community</h3>
                                <ul class="bordered-list">
                                    <li><a href="https://www.facebook.com/MysiteTeam" target="_blank">Facebook</a></li>
                                    <li><a href="https://twitter.com/mysiteteam" target="_blank">Twitter</a></li>
                                    <li><a href="https://www.youtube.com/user/mysiteteam" target="_blank">Youtube</a></li>
                                    <li><a href="https://www.instagram.com/mysiteteam/" target="_blank">Instagram</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </body>
</html>
<apex:actionFunction action="{!Save}" name="jsCallSavefn">  
</apex:actionFunction>
</apex:form>
</apex:page>

Controller,
 
public with sharing class CaseController {

    public Contact c { get; set; }
    
    public CaseController(){
       c = new Contact();
    }
    
    public Attachment attachment {
    get {
      if (attachment == null)
        attachment = new Attachment();
      return attachment;
    }
    set;
    }
     
    public string strSubject {get;set;}     
    public string strDescription {get;set;}     

    public PageReference save()
    {   
        String Body  = strDescription;

        String Subject = strSubject;
        List<String> toAddresses  = new List<String>();
        toAddresses.add('mysitesupportcase@z-279vlo46d4dn63rs8liuxfyuv0t1fjox5sgnsyr0nc6ccct0n0.m-4etgeaq.cs20.apex.sandbox.salesforce.com');
        toAddresses.add('ckarthikeyanbtechit@gmail.com');
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setSubject(Subject);
        mail.setReplyTo(c.Email);
        mail.setSenderDisplayName(c.Email);
        mail.setToAddresses(toAddresses);
        mail.setHtmlBody(body);
        if(attachment.body != null)
        {
            Blob b = attachment.body;
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            efa.setFileName(attachment.name);
            efa.setBody(b); 
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
        }       
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
        PageReference newocp = new PageReference('/apex/SampleRedirectPage');
        newocp.setRedirect(true);
        return newocp;
        return null;
    }
    
     
   
}

Can anyone fix this ASAP?

Thanks,
Varun SinghVarun Singh
hi try something like this in apex controoller in attachment method
 
if(attachment.size > 5242880){ 
          //maximum attachment size is 5MB.  Show an error
           ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Error, 'A "' + folderName0 + '" file was NOT uploaded, because it is too big (' + Decimal.valueOf(att0size/1048576).setScale(1) + ' MB): ' + att0name)); 
}

 
Varun SinghVarun Singh
Hi @Karthikeyan Chandran,

Implement your code
Blob MyBlob=attachment.body;
          if(MYBlob.size()>5242880)  
            {   ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'This file exceeds the maximum size limit of 5 MB.'));}
       
        
    }



 
Karthikeyan ChandranKarthikeyan Chandran
Hi Varun,

Sorry for the delay, i have tried your suggestion and it's not working for me.

Thanks
shyam singh 41shyam singh 41
Are you facing same problem please do the commnet.
Top Follow (https://topfollow.org) app is gain instagram followers.
momix armomix ar
still you are facing shym singh. i have any other same problem. is there any solution
momix apk (https://momixapk.com) download movie app.