I need to upload a file with ANSI character encoding from a VisualForce page and should be able to read the file and perform actions from Apex class(controller). Now when I upload an ANSI file, a StringException occurs:
BLOB is not a valid UTF-8 string.
VF page:
<apex:page Controller="FileParser">
<apex:include pageName="clcommon__mintTheme"/>
<apex:sectionHeader title="Upload File" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:pageMessages escape="false"/>
<apex:pageBlockSection columns="1">
<apex:inputFile value="{!bFile}"/>
<apex:commandButton value="Upload" action="{!processReturnFile}"/>
</apex:pageBlockSection>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
global with sharing class FileParser{
public Blob bFile {get; set; }
public PageReference processReturnFile(){
String strFile = bFile.toString();
System.debug(strFile );
}
}
I am getting this StringException while trying to do
String strFile = bFile.toString();
To create an ANSI file,
- Use characters like
SKårebj ø
and save file - Use online converters like this one to convert it to ANSI or 8859_1
I need the Controller(Apex class) to be able to read the text of this file. (System.debug(strFile );
in code)