4

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}"/>
</div>

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

enter image description here

3
  • I think you will get more response if you ask this question in stackoverflow
    – Ratan Paul
    Commented May 25, 2016 at 5:56
  • But this is related to apex tag. So I thought posting here will help me. Commented May 25, 2016 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
    Commented May 25, 2016 at 6:02

2 Answers 2

3

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.

VF:

<apex:page standardController="Document" extensions="documentExt" >
<apex:includeScript value="{!$Resource.exif}"/>
<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.LastModifiedDate = this.lastModifiedDate;
        document.querySelectorAll('[id$="desc"]')[0].value = JSON.stringify(obj); 
    });
} 
</script>
<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:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

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
}   }   

Demo:

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

3
  • 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") Commented May 26, 2016 at 6:32
  • It shows lastModifiedDate only in console log Commented May 26, 2016 at 6:53
  • lastModifiedDate could be taken from file property. Or from image audit propertis. Please check updated answer. Commented May 26, 2016 at 17:21
2

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/

1
  • Demo link is not working Commented May 25, 2016 at 7:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .