Hi Walid,
I have made a few tests with PNG files. The thing is actually feasible,
but the situation is not perfect.
As I was checking the spec to determine exactly what ReadAsBinaryString
is supposed to do and what a "binary string" exactly is, I discovered
that the W3C has updated the spec very recently (September 9th,
http://dev.w3.org/2006/webapi/FileAPI/#readAsBinaryString) and that
ReadAsBinaryString is already deprecated in favor of readAsArrayBuffer.
Of course they are perfectly entitled to do that as the spec is still a
draft and this is what drafts are made for.
Anyway, all browsers which implement the file API are still on the old
spec, so as of today, you are still supposed to use ReadAsBinaryString.
It turns out that a binary string is "a string, in which every byte is
represented by an integer in the range [0..255]". So there is no way you
can send that as iso8859-1, which is for latin text.
I think the safe way to manipulate it to convert it to base64 before
sending it. This way you will bypass all the encoding problems as base64
can be transmitted easily whatever the charset (utf-8, ascii, iso8859...)
To convert the image, add this function to your class:
private static native String base64encode(String str) /*-{
return $wnd.btoa(str);
}-*/;
Then you can call it like this:
String result64 = base64encode(reader.getResult());
Of course you will have to decode it from base64 on the server (how you
do that depends of course of the kind of server you are uploading to)...
and the content length of the uploaded file will be 4/3 larger as if you
were doing it in binary form directly.
I have updated the lib-gwt-file-test example in the SVN trunk to take
PNG into account (it still does not do any uploading but it displays the
dragged image correctly after having converted them as a base64 data url
in png, proving that ReadAsBinaryString + base64encode is a sound approach)
http://code.google.com/p/lib-gwt-file/source/list
Regards
Lukas