You need to sign in to do that
Don't have an account?

How to validate uploaded file as image
HI folks,
Can anyone tell me how to validate the uploaded file as image?
My vfp:
and my controller:
I dont know how to validate the blob data type
any help would be appreciatble
Thanks in advance
Karthick
Can anyone tell me how to validate the uploaded file as image?
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:form> </apex:page>
and my 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 validate here ConnectApi.BinaryInput b=new ConnectApi.BinaryInput(file,'image/jpeg','myimage'); ConnectApi.ChatterUsers.setPhoto(null,userinfo.getUserId(),b); } }
I dont know how to validate the blob data type
any help would be appreciatble
Thanks in advance
Karthick
All Answers
<apex:inputfile value="{!file}" onClick="TestFileType(this.form.uploadfile.value, ['gif', 'jpg', 'png', 'jpeg']);"></apex:inputfile>
Can you explain how the java script funtion is work?
and Is there any other method to validate the same?
Thanks in advance
Karthick
Is there any other way to valdiate the same?