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
Sonali GonnadeSonali Gonnade 

Blob or clob datatype not available in force.com

How to store images, video files in the database using force.com Objects.

Which data type needs to be used for the same.

Please suggest.

 

Thanks in advance.

 

Sonali Gonnade

Pradeep_NavatarPradeep_Navatar

Blob data type is available in Document object. Try using this to store the images :

 

            Below is the Sample code to save image in Document :

 

            ------------ VF Page Code -------------

            <apex:page Controller="SaveImgController"

                        <apex:inputFile value="{!propFileBody}" fileName="{!propFileName}" contentType="{!propContentType}"/>

                        <apex:commandButton value="SameImage" action="{!SaveImg}" />

            </apex:page>           

 

            ------------ Controller Code -------------

            public class SaveImgController

            {

                        public String  propFileName{ get; set; }

                        public Transient Blob propFileBody{ get; set; }

                        public String  propContentType{ get; set; }

 

                        public void SaveImg()

                        {

                                    Folder fd = [Select id, name From Folder Where name = 'My Personal Documents'];

                                    Document doc = new Document();

                                    doc.Name = propFileName;

                                    doc.Body = propFileBody;

                                    doc.ContentType = propContentType;

                                    doc.Type = propContentType.substring((propContentType.indexOf('/')+1),propContentType.length());

                                    doc.IsPublic = true;

                                    doc.FolderId = fd.id;

                                    Database.SaveResult sr = Database.Insert(doc);

                        }

            }

 

Hope this helps.

Sonali GonnadeSonali Gonnade

Thanks a lot for your quick help. Definitely it will help us for our application.

 

Sonali