Can any one suggest if there is any package or useful link for this.

As of now, I have a button on my visualforce page, where I can upload one document. If i select another document again, the 1st one is over writed. So, here can any one suggest how to add multiple attachments using one button. Like in gmail, we add attachments.

I am just looking for useful link. As far I have searched, I wasn;'t able to find. I will be able to write the code, based on the suggested link or package.

Thanks in advance..


There is no visualforce native solution to this. But you can use HTML5 to achieve this.

<input type="file" name="files[]" multiple="multiple" onchange="uploadFiles(this);"/>

and catch the files in input.files array in JavaScript.

     <script type="text/javascript">
        function uploadFiles(input)
            for(var i =0; i<input.files.length; i++)
                var filesizeInBytes = input.files[i].size;
                var filename = input.files[i].name;
                console.log("File name is : "+input.files[i].name+" and  size : "+input.files[i].size+" Bytes");                    


You can utilize this blog to read the files uploaded and send to apex controller.

  • Santanu, this working when i add multiple files at a time. If i select one file and after selecting the first one, if select 2nd one in another instance then 1st one is lost. Can you suggest how to overcome this? – venky Apr 28 '17 at 12:50
  • Not sure, but I think you can keep an array declared outside uploadFiles function and dump all items from input.files into that.. so in a way, that array will keep all the files selected in different instances. – Santanu Halder Apr 28 '17 at 13:46
  • Use the script on this blog to bypass the limit kevansfdc.blogspot.com/2017/05/… – Kevan May 15 '17 at 10:34
  • Hi Santanu how can i get the files content once the file is passed to apex controller not through ajax.Is there other way around. – Deepak Agarwal Apr 19 at 9:38
  • @DeepakAgarwal, that depends upon how you are sending the file body to apex. I would suggest you to open a new question about it and we should be able to help you better. – Santanu Halder Apr 22 at 7:15

Check this out venky in the official dev forum : developer forum

  • Thanks for sharing this link, but it consist of multiple buttons for multiple attachments. – venky Apr 28 '17 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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