+ Start a Discussion
Jyoti Singh 9Jyoti Singh 9 

Salesforce1 - Is it possible to open camera?

Is it possible to launch camera app from Salesforce1?
KaranrajKaranraj
All you have to do is to use “accept” attribute of “apex:inputfile”. accept=”image/*;capture=camera” will inform device that current application (in our case Salesforce1) needs to access Camera of device.

Check this greap post on accessing camera from salesforce1 http://www.jitendrazaa.com/blog/salesforce/access-camera-and-audio-recorder-of-mobile-device-in-visualforce-and-upload-as-chatter-file/
Jyoti Singh 9Jyoti Singh 9
How do I save it? Can you please provide sample code?
Abraham PaulAbraham Paul
All we have to do is to use “accept” attribute of “apex:inputfile”. accept=”image/*;capture=camera” will inform device that current application (in our case Salesforce1) needs to access Camera of device.

//To take snap from Camera
accept=”image/*;capture=camera”
//To record Video
accept=”video/*;capture=camcorder”
//To record Audio
accept=”audio/*;capture=microphone”
Note : Safari / Iphone does not support microphone recording


Apex Controller :
/**
2 * Created By   :   Vlogging Guru (https://vloggingguru.com)
3 * Date         :   27 Mar 2020
4 * Description  :   Demo of accessing Camera using Visualforce and uploading file in Chatter.
5 *              :   Article on https://vloggingguru.com
6 * */
7public class CameraAccess{
8    public ContentVersion cont {get;set;}

10    public CameraAccess() {
11        cont = new ContentVersion();
12    }     
13 
14    public PageReference saveFile()
15    {
16        //PathOnClient is Mandatory
17        cont.PathOnClient = cont.title;
18 
19        //By default Origin value is "C" that means Content must be enabled in Org, so we need to explicitly set Origin as H
20        cont.Origin = 'H';
21        insert cont;
22 
23        //redirect to path where file is saved
24        return new PageReference('/'+cont.id);
25    }
26}


Visualforce Page :
<apex:page controller="CameraAccess" standardStylesheets="false" showHeader="false">

3 <apex:stylesheet value="{!URLFOR($Resource.BootStrap3, '/bootstrap-3.1.1-dist/css/bootstrap.css')}" />
4 <div class="container">
5    <div class="row clearfix">
6        <div class="col-md-12 column">
7            <div class="jumbotron">
8                <h1> Camera Access in Visualforce using HTML 5 </h1>
9                <a href="https://vloggingguru.com">Vlogging Guru</a>
10            </div>
11            <div class="panel panel-warning">
12                <div class="panel-heading">
13                    <apex:form>
14                     <p>
15                        <apex:inputFile value="{!cont.VersionData}"  accept="image/*;capture=camera" filename="{!cont.Title}" />
16                     </p>
17 
18                     <p>
19                        <apex:commandButton StyleClass="btn btn-danger" action="{!saveFile}" value="Save File" />
20                     </p>
21                    </apex:form>
22                </div>
23            </div>
24        </div>
25    </div>
26</div>
27 
28</apex:page>