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
Chidambar KulkarniChidambar Kulkarni 

Attach camera pic to a custom object

Hi,

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

Thanks
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() {
  $("#photoFile").change(handlePhoto);
});

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){
        alert(JSON.stringify(error));
      });
    };
  })(file);

  reader.readAsDataURL(file);
}
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.

Regards,
Nagendra.P
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"