I want to get the details of the uploaded image

To choose Image I am using following code in VF

<div class="form-group">
<label class="lbl">Image</label>
<apex:inputFile value="{!att.Body}" fileName="{!att.Name}" contentType="{!att.ContentType}"/>

I want to get Location info and Created date of Image.

enter image description here

  • I think you will get more response if you ask this question in stackoverflow – Ratan Paul May 25 '16 at 5:56
  • But this is related to apex tag. So I thought posting here will help me. – SFDC shaikh May 25 '16 at 5:59
  • yeah you can ask here. just wanted share my thought since it is a simple input type="file" you could ask in main stackoverflow site there so many member having more knowledge about JS . May be they have any any solution just guessing – Ratan Paul May 25 '16 at 6:02

Following page utilizes Exchangeable Image File library and apex:inputfile example. Exif.getData function reads GPS data from image and stores it as description in document record.


<apex:page standardController="Document" extensions="documentExt" >
<apex:includeScript value="{!$Resource.exif}"/>
function getGPSdata(e) { 
    EXIF.getData(e.files[0], function() {
        var obj = {};
        obj.Latitude = EXIF.getTag(this, "GPSLatitude");
        obj.Longitude = EXIF.getTag(this, "GPSLongitude");
        obj.LastModifiedDate = this.lastModifiedDate;
        document.querySelectorAll('[id$="desc"]')[0].value = JSON.stringify(obj); 
<apex:messages />
<apex:form >
    <apex:pageBlock >  
        <apex:pageBlockSection columns="1">
            <apex:inputFile value="{!document.body}" filename="{!document.name}"
                            onchange="getGPSdata(this)" />
            <apex:inputField value="{!document.description}" id="desc" />
            <apex:commandButton value="Save" action="{!save}"/>

Apex left unmodifed:

public class documentExt {
public documentExt(ApexPages.StandardController controller) {
    Document d = (Document) controller.getRecord();
    d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
}   }   


Pass exif propery to apex

Exif tags could be found here

Don't forget to create static resource with name exif and upload exif.js file

  • Hi Ilya Lapesh, Thank you so much Its working fine. Now hot to fetch Created date? I tried EXIF.getTag(this, "DateTime") and EXIF.getTag(this, "DateTimeOriginal") – SFDC shaikh May 26 '16 at 6:32
  • It shows lastModifiedDate only in console log – SFDC shaikh May 26 '16 at 6:53
  • lastModifiedDate could be taken from file property. Or from image audit propertis. Please check updated answer. – Ilya Lepesh May 26 '16 at 17:21

To get the location info of the image you have to read EXIF info of the image. I do not know whether Apex has out of the box methods to do it. Any body can let me know if it is there.

But you can do this with jQuery with jQuery fileEXIF plugin.

Here are some tutorials links.

How to get EXIF data from images using jQuery - http://rrike.sh/jquery/how-to-get-exif-data-from-images-using-jquery/

Demo Link - http://jsfiddle.net/noonon/Ls5Dw/

  • Demo link is not working – SFDC shaikh May 25 '16 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.