How to access Camera option in Vf Page

My Apex Code is:

public class CameraAccess{
    public ContentVersion cont {get;set;}

    public CameraAccess() {
        cont = new ContentVersion();

    public PageReference saveFile()
        //Here how i need to save this...
  • 2
    You can not access camera through Apex code, so no point sharing the apex code. This thread will help. Apr 12, 2017 at 9:14
  • How to Give Path on Client...
    – Anjaan
    Apr 12, 2017 at 9:20

1 Answer 1


In mobile devices, you can access camera by using accept="image/*;capture=camera" in <apex:inputFile element. Use ContentVersion object to store the file.

VF Page

<apex:page standardController="Document" extensions="CapturePhoto" standardStylesheets="false" showHeader="false">
    <apex:form id="theForm">
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!savePhoto}" status="status"/>
            <apex:pageBlockSection >
                <apex:inputFile value="{!cont.VersionData}" fileName="{!cont.Title}" accept="image/*;capture=camera"/>


public class CapturePhoto {
    public ContentVersion cont {get;set;}
    public CapturePhoto(Apexpages.StandardController controller){
        cont = new ContentVersion();
    public pageReference savePhoto(){
            cont.PathOnClient = cont.title;
            cont.Origin = 'H';
            insert cont;
            return new PageReference('/'+cont.id);
        }catch(Exception ex){
            System.debug('@@'+ ex.getMessage());
        return Apexpages.currentpage();          

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .