You need to sign in to do that
Don't have an account?
bibbo84
BLOB is not a valid UTF-8 string and € symbol
Hi to all.
I'm trying to build a loader for csv file. As you can see from the code I load my csv file in an attachment. After I take the body of the attachment and insert it into a string using the toString (). I noticed that when in the csv file there is the € symbol I get an exception of type 'BLOB is not a valid UTF-8 string'. Do you have any suggestion?
My Controller
public with sharing class DocumentwithEuroController { public Attachment document { get { if (document == null) document = new Attachment(); return document; } set; } public PageReference checkFile() { String fileBody = ''; try{ fileBody = document.body.toString(); system.debug(fileBody); }catch(exception e){ if(e.getmessage() == 'BLOB is not a valid UTF-8 string'){ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, 'In the csv file there are stressed symbols. The upload is blocked')); } } return null; } }
My page.
<apex:page controller="DocumentwithEuroController" > <apex:form > <apex:pageMessages id="pms1" /> <label for="ifl" style="text-align: left; font-weight: bold; padding-right: 0.69em;">Selezionare il file tracciato(.csv):</label> <apex:inputFile id="ifl" value="{!document.body}" filename="{!document.name}" styleclass="btn" /> <apex:commandButton value="Load csv" action="{!checkFile}" status="loadCsv" /> </apex:form> </apex:page>
For me is very important, i must resolve this proble by tomorrow
Tanks to all,
FP
Is there a way to automatically convert in utf-8 my csv file on loading? I can't ask my customer to convert the file.
https://www.codengine.in/2019/06/blob-is-not-a-valid-utf-8-string-salesforce-apex.html