Can anyone tell me how to validate the uploaded file is image using blob data type?
My vfp:
< apex:page standardController="Contact" sidebar="false" extensions="DpConnectApiExt">
< apex:form >
<apex:outputPanel id="ProfilePicturePanel">
<apex:pageMessages ></apex:pageMessages>
<apex:outputText ><b>Current User Profile Picture Using Connect API</b></apex:outputText><br/>
<apex:actionRegion >
<center> <apex:image url="{!UserfullPhoto}" /> </center><br/><br/>
</apex:actionRegion>
</apex:outputPanel>
<apex:outputtext > <b> Uploading Image Via Connet API </b></apex:outputtext>
<apex:inputfile value="{!file}"></apex:inputfile>
<apex:commandButton value="Submit" action="{!upload}" />
<apex:detail subject="{!Contact.Id}" title="false" relatedListHover="false"/>
</apex:form>
</apex:page>
Controller:
global class DpConnectApiExt {
global String UserfullPhoto { get; set; }
global transient Blob file{get;set;}
global DpConnectApiExt(ApexPages.StandardController controller) {
ConnectApi.Photo p = ConnectApi.ChatterUsers.getPhoto(null, UserInfo.getUserId());
UserfullPhoto =p.fullEmailPhotoUrl;
}
public void upload(){
system.debug('File:'+file);
**//I want to handle here**
ConnectApi.BinaryInput b=new ConnectApi.BinaryInput(file,'image/jpeg','myimage');
ConnectApi.ChatterUsers.setPhoto(null,userinfo.getUserId(),b);
}
}
Thanks in advance
Karthick