function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dai developerdai developer 

Binary .dat file

Hello,

I have to import a file and read it (and validate the data) but cannot.

It has ".dat" extension and can edit it with notepad without a problem but with <inputfile> the body (utf8 encoded)
of the file is an unreadable sequence of chars (bytes?).

If i edit the file.dat with an editor and save it as .csv, my code works perfect(even break lines stay) but, curious enough, if i simply change
the file.dat extension to csv, i obtain the same unreadable string.

The code:

<apex:page controller="c_CargaFicheroPedidoController">
   
     <apex:form >
        <apex:pagemessages /> 
        <apex:pageBlock >
            <apex:pageBlockSection columns="4">
                
                  <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}" contentType="text/plain"/>

the controller

string dddfff = EncodingUtil.base64Encode(csvFileBody);

Thanks everybody



Best Answer chosen by dai developer
dai developerdai developer
Someone solved my problem and another one showed me the solution which is here:

 http://salesforce.stackexchange.com/questions/11805/blob-is-not-a-valid-utf-8-string-error