Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting UploadedFile to String

843844Feb 27 2008 — edited Mar 2 2008
hi 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!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 30 2008
Added on Feb 27 2008
4 comments
488 views