2

Is it possible to set an encoding for a file that is uploaded via a VisualForce page? I am getting errors stating that the content of the uploaded file is not UTF-8 encoded. Ideally, the user would be able to specify the file encoding himself, similar to the Account and Contact import wizard.

2
  • You want to upload your files in static resource ?? Please provide more information !! Jun 3, 2013 at 7:54
  • I just want to post a CSV file via a form and process its contents, not saving it in salesforce. Jun 3, 2013 at 9:27

1 Answer 1

2

Assuming your CSV file is being processed by a VF controller as part of a binding from the apex:inputFile component to a controller variable of type Blob, then, if you want to manipulate the CSV contents in the controller, the Blob must be converted to a String using Blob instance method myBlob.toString().

This toString() method requires that the Blob contain only UTF-8 characters as all Apex string operations are done in UTF-8.

Conclusion, the uploaded file when presented to the VF page has to be in UTF-8 before the page action executes.

2
  • Thanks, that answers the question. Our "fix" is to extend our documentation so that users know how to produce valid UTF-8 documents. Salesforce drives me crazy sometimes… Jan 14, 2014 at 10:57
  • Be sure to let your users know that MSFT Excel will not save CSV files in UTF-8 unless they start in UTF-8. You need to use Google docs, Open Office, or convert the file using Notepad or other text editor. If all the chars are ASCII A-Z, a-z, 0-9 and common punctuation, then ASCII = UTF-8
    – cropredy
    Jan 14, 2014 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.