ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Location & Metadata Retrieval from Image in Visualforce Page

Home / Article & Blogs / Apex / Location & Metadata Retrieval from Image in Visualforce Page
By Team ABSYZ inApex, Salesforce

Hi All,

Recently I was working on a requirement where I had to extract the data stored in an image file, data like the location where the image was taken and the date of image capture is classified data which is embed in the image/picture itself. After doing some research on this topic, I found out a way to extract this data from an image, which I thought it would be helpful for all of us, if we have resource/blog to refer it later on similar requirements.

Many of us don’t know that when we capture the image, it will store the date, size, dimensions, ISO, Device that captured and Location details(If GPS is on in GPS Supported devices like Mobile,DSLR, etc..).

For Example, I have taken the below image from my mobile device with my GPS switched on and imported the same to my laptop.

 

IMG_20170729_085531

To view the information that got captured: Right click on Image file.Click on properties, you will be able see like following screen.

blog1

Now Click on the details Tab and scroll down to see the below details:

blog2

blog3

Now, we can extract this information from the image when it is uploaded into our Salesforce org. We can achieve this using the below procedures:

As part of this demo I am extracting Longitude, latitude and captured date from the picture and display in one field in Salesforce called ‘Description’ on File Object.But we can extract every element in the above attributes using EXIF Data.

Implementation:

First we should include a javascript EXIF library as a static resource. You can find the EXIF Library code in This File . Put this code in a text document and save it as ExifJavaScript.js file. à Upload that file as static resource with name ‘ExifJavaScript’ to use it in visualforce page.

Visualforce Page:

[sourcecode language=”java”]
<apex:page controller=”CreateSnap” standardStylesheets=”false” showHeader=”false”>
<apex:includeScript value=”{!$Resource.ExifJavaScript}”/>
<script> function getGPSdata(e) {
EXIF.getData(e.files[0], function() {
var obj = {};
obj.Latitude = EXIF.getTag(this, “GPSLatitude”);
obj.Longitude = EXIF.getTag(this, “GPSLongitude”);
obj.CreatedDate = EXIF.getTag(this,”DateTime”);
document.querySelectorAll(‘[id$=”desc”]’)[0].value = JSON.stringify(obj); });}
</script>
<div class=”container” style=”background-color:#E6E6FA”>
<div class=”row clearfix”>
<div class=”col-md-12 column”>
<div class=”jumbotron”>
<h1> Camera Access in Visualforce using HTML 5</h1>
</div>
<div class=”panel panel-warning”>
<div class=”panel-heading”>
<apex:form >

<apex:inputFile value=”{!cont.VersionData}” accept=”image/*;capture=camera” filename=”{!cont.Title}” onchange=”getGPSdata(this)”/>

<apex:inputTextarea value=”{!cont.description}” id=”desc” rows=”7″ cols=”25″ disabled=”true” >

<apex:commandButton StyleClass=”btn btn-danger” action=”{!saveFile}” value=”Save File” >

</apex:form></div>
</div>
</div>
</div>
</div>
</apex:page>
[/sourcecode]

Apex Class:

[sourcecode language=”java”]

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

public CreateSnap() {
cont = new ContentVersion();
}

public PageReference saveFile()
{
//PathOnClient is Mandatory
cont.PathOnClient = cont.title;
cont.Description = cont.Description;
//By default Origin value is “C” that means Content must be enabled in Org, so we need to explicitly set Origin as H
cont.Origin = ‘H’;
insert cont;

//redirect to path where file is saved
return new PageReference(‘/’+cont.id);
}
}

[/sourcecode]

We can use all tags available in the above JavaScript library by using following code in visualforce Page.

[sourcecode language=”java”]

<apex:includeScript value=”{!$Resource.ExifJavaScript}”/>

[/sourcecode]

We are calling this piece of javascript code from

[sourcecode language=”java”]

function getGPSdata(e) {

EXIF.getData(e.files[0], function() {

var obj = {};

obj.Latitude = EXIF.getTag(this, “GPSLatitude”);

obj.Longitude = EXIF.getTag(this, “GPSLongitude”);

obj.CreatedDate = EXIF.getTag(this,”DateTime”);

document.querySelectorAll(‘[id$=”desc”]’)[0].value = JSON.stringify(obj);

});

}

[/sourcecode]

The tags such as GPSLatitude, GPSLongitude, DateTime are available from the EXIFJavaScript file which has been included in this VisualForce page as a Static Resource.

We are Creating a variable called ‘obj’to store the data returned from the library. So, obj.Latitude, obj.Longitude, obj.CreatedDate contains the date we need.

The following line will find the Tag with Id named as ‘Desc’ and will store the data from that tag to the ‘Description’ field of ‘ContentVersion’ in our case.

[sourcecode language=”java”]
document.querySelectorAll(‘[id$=”desc”]’)[0].value = JSON.stringify(obj);
[/sourcecode]

For Uploading our image into salesforce I have used apex:inputFile. This will store the image file in VersionData Of ContentVersion Object.

 

[sourcecode language=”java”]
<apex:inputFile value=”{!cont.VersionData}” accept=”image/*;capture=camera” filename=”{!cont.Title}” onchange=”getGPSdata(this)”/>
[/sourcecode]

Whenever an image gets selected in this File our Javascript fuction will be called and we will get the data in the Description field of ContentVersion in JSON Format.

On clicking Save we are calling our Controller method to save Data in Back-end and redirection it our result screen as well.

Output:

blog 4

Click on ‘Choose File’ to select the image.

blog 6

Click on Open to selected file

blog 7

Click on ‘Save File’ to save image in backend and as well as storing the fetched information in description filed as follow.

blog 8

We are not restricted to only the few information shown above, we can get device information by using ‘Model’ tag and we can get comments added by the user who has created etc.

Use Cases:
  1. Helps to efficiently determine whether an image is genuine and authentic.
  2. Helps to track/verify work progress based on images
  3. Useful to organize and segregate photographs based on their location.
  4. If you have clicked a picture and later do not recollect where you had clicked it, it helps to easily find the location your picture was taken at.
Limitations:

1. Maximum view state size limit (135KB).

2. The maximum file size that can be uploaded via Visualforce is 10 MB.

 

GeoTaggingImage Info RetrievalJavascriptMetaData
75
Like this post
127 Posts
Team ABSYZ

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostINTRODUCTION TO SALESFORCE IoT CLOUD
  • Next PostWinter '18: Uploading Files in lightning Component

Related Posts

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Automation in Healthcare And Its Benefits
Health Cloud Salesforce

Automation in Healthcare And Its Benefits

7 Comments

  1. Aquib Javed
    Reply
    17 October 2017

    Great post. Can we use the same for Salesforce 1 ?

    Reply
    • arunlivecom
      Reply
      17 October 2017

      Yes We can use in Salesforce 1

      Reply
  2. Saud Ahmad
    Reply
    28 November 2017

    Where are these files get stored?

    Reply
    • arunlivecom
      Reply
      28 November 2017

      ContentVersion is a standard Object and it has a field called Description. We are storing that information in this field itself

      Reply
  3. max
    Reply
    29 March 2018

    1. can we get the psychical location instated of the Geo location ?
    2.how can we add the store name and number (means store number ex Costco #899) where i clicked the picture in store ?

    Reply
  4. Karina Santos
    Reply
    18 May 2018

    Hello, have you written a test class for this?

    Reply
  5. nkopparthi
    Reply
    7 September 2018

    Hi Arun,

    I am trying to get the EXIF data for an picture that is being displayed on a VF page. Not during file upload. I loaded the latest exif-js and included it via the apex:includeScript tag. I made a slight modification to your code as follows:

    function getExif() {
    var img1 = $(“.ltng.img-thumbnail.center-block”);
    EXIF.getData(img1, function() {
    var make = EXIF.getTag(this, “Make”);
    var model = EXIF.getTag(this, “Model”);
    console.log(`${make} ${model}`);
    });
    }

    and then i call getExif();

    I am getting undefined. Any help would be great!

    Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT