Converting UploadedFile to String
843844Feb 27 2008 — edited Mar 2 2008hi all,
i'm using tomahawk's <t:inputFileUpload> to upload files and save them in MySQL database to a MEDUIMBLOB field; and coz i'm using EJB3.0, the entity EJB of that table containing the saved files has mapped MySQL datatype MEDUIMBLOB to java String datatype .. the <t:inputFileUpload> returns an "UploadedFile" instance; so i need to extract the file contents (not content type) and place them in a String, i tried to do that somehow but when i download the file from the database i appears in a strange encoding.
here's the code i tried:
// myFile is the UploadedFile instance
Long fileSize = myFile.getSize();
int fileSizeInt = fileSize.intValue();
byte[] byteFile = new byte[fileSizeInt];
InputStream fileStream = myFile.getInputStream();
fileStream.read(byteFile, 0, fileSizeInt);
String stringFile = new String (byteFile);
i dont know if the error is in the conversion code or in the database so plz anyone has any suggestion!!