Menu

#10 Plain Image corrupted

pending-rejected
nobody
SUPA Applet (5)
5
2011-10-27
2011-07-19
No

When using NullEncoding the method getEncodedString() returns new String(encodedBytes) which is charset-dependant and hence not a valid stream.

For example when I try to upload an image as plain byte stream a 00 byte is encoded as EF BF BD which leads to corrupted images.
(Firefox 5.0, Vista 64, german)

Altough I do not really know how to circumvent this issue I would try to return new String(encodedBytes, "US-ASCII") but unfortunately I cannot start the applet when it is not signed. - or can I somehow?

Discussion

  • Michael Schwartz

    I managed to compile and sign the module by myself but was not able to find a working js-applet configuration which sends the plain image to the server without unicode-transformation hazzles.
    Even applet.getBytes() and a for-loop with String.fromCharCode was not successful :-) Any help is appreciated.

     
  • Michael Schwartz

    Since there was no help here I managed to do it the other way around although it was not possible without a hack:

    I changed Supa.js to upload the file in mantis-style (mantis is a bugtracker, see mantisbt.org) and attached the file base64-encoded. To be able to distinguish between plain files and base64 files I set the Content-Type to "image/base64png" during upload. On the server-side I tweaked mantis to recognize the content-type, decode the attached file and proceed with the upload.

    The sourcecode is attached to the following page:
    http://www.mantisbt.org/forums/viewtopic.php?f=9&t=19573

    The issue there is written in german language but in principle there is the same information as in this note.

    Although the original question is unsolved I managed to do what I wanted to do so it is time to close the issue.

     
  • Christoph

    Christoph - 2011-10-27
    • status: open --> pending-rejected
     
  • Christoph

    Christoph - 2011-10-27

    Sorry for the long delay, I got another job and moved to another country :)

    Short story: base64 is the way to go!

    Long story:
    Javascript just does not have a concept of binary data!
    Just converting a binary blob directly to a string will result in characters codes of unprintable characters. These get mapped to a specified "non printable character" code and the original data is thereby destroyed.
    That's why we *have* to use some encoding (namely base64) that converts binary to something Javascript can handle.

    The getBytes() method is just there for debugging purposes.

     

Log in to post a comment.