VF
<apex:inputFile value="{!FileBody}" filename="{!FileName}" accept=".doc,.docx,.pdf,.xlsx,.xls" />
Apex
public String create_file_param_file(String boundary, String name, String val1 , Blob val2){
List<String> names = val1.split('\\.');
String fileName = names[names.size()-1].toLowerCase();
String transferEncoding = 'Content-Transfer-Encoding: base64'+ '\r\n';
String fileData = 'Content-Transfer-Encoding: base64'+ '\r\n';
String contentType;
if(fileName=='pdf'){
contentType = 'Content-Type: application/pdf';
fileData = transferEncoding + '\r\n'+ EncodingUtil.base64Encode(val2);
}else if(fileName =='xls'){
contentType = 'Content-Type: vnd.ms-excel';
fileData = transferEncoding + '\r\n'+ EncodingUtil.base64Encode(val2);
}else if(fileName=='xlsx'){
contentType = 'Content-Type: vnd.openxmlformats-officedocument.spreadsheetml.sheet';
fileData = transferEncoding + '\r\n'+ EncodingUtil.base64Encode(val2);
}else if(fileName=='docx'){
contentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
fileData = transferEncoding + '\r\n'+ EncodingUtil.base64Encode(val2);
}else{
contentType = 'Content-Type: text/plain';
fileData = '\r\n' +val2.toString();
}
String param = '--' + boundary+'\r\n'
+ 'Content-Disposition: form-data; name="' + name + '"; filename="' + val1 + '"' + '\r\n'
+ 'Content-Type: '+contentType + '\r\n'
+ fileData + '\r\n';
return param;
}