[SalesForce] Upload attachment in VisualForce without reloading the whole page

I have a modal window on page, to add attachment. On completion of addition, I have to close the modal window and refresh the attachment details section.

But, I am getting an error if I try to reload a particular section after adding attachment.

apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

How to resolve this issue? Is there a workaround for this, without reloading the whole page(or using an iFrame)? Or, do we need to replace with some JS library?

Best Answer

You can use Javascript remoting to upload file. However it will reqire understanding of Javascript.

Steps are as follow:

  1. Pull file details from input type file using js File API
  2. Send it using javascript remoting
  3. Upload that file in apex function bound with javascript remoting
  4. Get the status on VF page and show message

No reloading required.

Related Topic