+ Start a Discussion
Chidambar KulkarniChidambar Kulkarni 

Attach camera pic to a custom object


How do i attach a photo (as a field) to a custom object?

I am able to open the camera & file browser using the statement below 
<input id="photoFile" type="file" accept="image/*"/>

Custom Object Name: PVID
How do I save and attach it with the Custom Object?

Any help appreciated

NagendraNagendra (Salesforce Developers) 
Hi Kulkarni,

You can access the camera from a Salesforce1 app, using the HTML <input> tag with accept="image/*" to access either the camera or photo library, for example
<input id="photoFile" type="file" accept="image/*"/>
You can then use the HTML5 File API to upload image data. Here's an example using the Force.com REST API - you would change this to process the QR code as necessary.
$(document).ready(function() {

function handlePhoto(evt){
  var file = evt.target.files[0];
  var reader = new FileReader();

  reader.onload = (function(theFile) {
    return function(e) {
      // Extract raw base64 data from data URL
      imageData = e.target.result.split(',')[1];

      forcetkClient.create('ContentVersion', {
        "Origin": "H",
        "PathOnClient": file.name;,
        "VersionData": imageData
      }, function(data) {
        $('#status').html("<p>Uploaded image</p>");
      }, function(error){

The Dreamforce 2013 session Only One Cure for the App Boogie Fever demonstrates this technique(https://www.youtube.com/watch?v=ZK0cb40f-G4)

Please let us know if this helps.

Chidambar KulkarniChidambar Kulkarni

Hi Nagendra,

Thanks for the reply.

There still seems to be a problem.
1. When I upload an image, the visualforce page refreshes(within a sec) and the attachment as well other data is lot
2. How do I attach the image to the PVID object? So, that it displays in the details after I hit "Submit"