+ 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


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}" />



            ------------ 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.