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
Daft PunkDaft Punk 

Can I use input type="file" in place of apex:inputFile?

The majority of my VF page is built dynamically with jQuery. I'm looking to upload some attachments, I can accomplish this with inputFile, but I can't use any apex elements because everything else on the page is made with jQuery, body, tables etc...

So can I replace

    <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" title="Upload Attachment" styleclass="fileType"/> 

with this
   
<input type="file" value="{!attachment.body}" name="{!attachment.name}" id="file" accept="image/jpeg, image/png"> </input>


     
Best Answer chosen by thisisnotapril
Varun VatsaVarun Vatsa
yes..you surely can...but then you would have to take care of assinging the uploaded file to a variable..and insert it into object.

All Answers

Varun VatsaVarun Vatsa
yes..you surely can...but then you would have to take care of assinging the uploaded file to a variable..and insert it into object.
This was selected as the best answer
MagulanDuraipandianMagulanDuraipandian
Yes.

If this solves your problem, kindly mark it as the best answer.

Regards,
Magulan
http://www.infallibletechie.com
Daft PunkDaft Punk
Thanks Varun,

Would you possibly have any suggestions as to what might be the best approach for this?

Or perhas some sample code?
Varun VatsaVarun Vatsa
Hi Daft, 

You may use a Remote Action method, which mean you can write a method in apex and may call it from JQuery, you need to pass in as parameter a base64encoded string (Convert file in base 64 ) and then in method you may decode it to upload it.
Sunil PalSunil Pal
HI Daft Punk

Can you please share you code sample how you achieved this I have the same scenario but not able to resolve it.

Thanks