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

How to get file body using input type file

Hai all,



      i have a problem in getting file body  using     input type="file" name="file"  to the controller for insert a attachment 


where as i am getting file body directly using

visualforce page

 <apex:inputfile value="{!filebody}" filename="{!filename}"/>




  Attachment myAttachment = new Attachment();
        myAttachment.Body = fileBody;                         //line 1
        myAttachment.Name = fileName;  
        myAttachment.ParentId = CurrentParentId;          
        insert myAttachment; 


but the reason why i am asking only by input type=" file" because i have to upload multiple files(multi attchments) which is not possible using apex:inputfile


like line 1 how can i get file body using input type="file" to the controller


please help me in sloving this problem its bit urgent

thanks anoop for your reply
in that link it is for selecting individual file selecting but i am trying to select multiple files at a time using
<input type="file" multiple="true" />
using java script i have to send file body to controller
Hi Anoop,

ya anoop your right apex:inputFile only support one file at a time so that is why i am using <input type="file" multiple="true"> for multiple files at a time...
i am able to pass multiple file names and size from visualforce page to controller using javascript but i am getting problem in passing file content
how to get file content into java script when we are using
<input type="file" multiple="true">
Anoop yadavAnoop yadav
Hi Ran,

I found one link that supports multiple file at a time.
But not sure how they are using
just chek this link:
Hai Anoop,

i am already using that code it is working fine till 1.27 MB but in salesforce standard uploading we are uploading upto 5 MB
so it will not work for larger file like 3 MB
Santosh Saha 10Santosh Saha 10
Hello Ran,

Did you get the solution  ?

If yes please help by posting the Solution

Warm Regards
Sunil PalSunil Pal
HI Ran

Can please share the code how you are able to pass the file name and size to controller. I am having the same scenaio in which I need to pass two or more than two file content at a time. Please share