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
Prem ChauhanPrem Chauhan 

how to upload image through visualforce page and store in salesforce

Hi Everyone,

Let me know the solution please: How to upload an image through Visualforce page and store in salesforce custom object and display in Custom object detail page. 

It's urgent.  
Note: When users fill all the data with an Image after a click on the save button then all those details and including inserted image should get save first and then display in that custom object detail page.  

Many thanks in advance. 
Deepali KulshresthaDeepali Kulshrestha
Hi Prem,
Please follow the given below steps and links with the help of these, you can solve your problem, it may be helpful to you.

A very common requirement we come across is uploading image/photo through vf pages. While doing this task we need to keep in mind that we can't directly display the image in visualforce page in salesforce. It should be stored at someplace- There are 3 places where we can store our images

1. Documents
2. Static Resources
3. Attachments.

Below We are illustrating an example of uploading and displaying image in visualforce using Documents sobject inside link.

In below link, there is another similar example to your problem.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Krishnaveni A 2Krishnaveni A 2
Hi Prem,
     I have tried this out using a simple VF page. Please try it out and confirm whether this is what you are expecting. Below is the code and sample screenshots.

   I have created a rich text area field in Salesforce and utilized that field in VF page. Is that okay? I assume that the end user will be uploding the image via VF page only.

VF Page:
<apex:page standardController="Account" showHeader="false">
<apex:pageblock title="New Account" >
  <apex:pageBlockSection columns="2">
      <apex:inputField value="{!Account.Name}"/>
      <apex:inputField value="{!Account.Type}"/>
      <apex:inputField value="{!Account.AccountNumber}"/>
      <apex:inputField value="{!Account.KV_SF__Insert_Image__c}"/>      
      <div align="center" draggable="false" >
      <apex:commandButton style="aligntext-center" action="{!Save}" value="Save Account"/>
This screenshot is from VF page and after clicking the 'save account' button in page, it will redirect to the salesforce record.
User-added image
This screenshot is from salesforce where the image inserted via VF page is displayed in object detail page.
User-added image
Hope this helps. Thanks!