Base64 strange problem

T

Tamir Weiss

I'm trying to send a byte array (JPG image) from javascript to a
servlet for processing.
I'm using Base64 to encode the byte array in javascript, and then a
base64 decoder in the servlet to decode it.

The thing is, that even though the String has the same length on both
sides, the decoded byte array is shorter then the original one.
I've tried a couple of different implementation on both sides, with
the same results.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
glegroups.com>, Mon, 14 May 2007 10:10:44, Tamir Weiss
I'm trying to send a byte array (JPG image) from javascript to a
servlet for processing.
I'm using Base64 to encode the byte array in javascript, and then a
base64 decoder in the servlet to decode it.

The thing is, that even though the String has the same length on both
sides, the decoded byte array is shorter then the original one.
I've tried a couple of different implementation on both sides, with
the same results.

It is clear what your problem is; it is that you have done something
wrong.

A better description of what code you use might render possible a more
specific response. However, as you asked no question, you may not be
expecting any answer.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
V

VK

I'm trying to send a byte array (JPG image) from javascript to a
servlet for processing.
I'm using Base64 to encode the byte array in javascript, and then a
base64 decoder in the servlet to decode it.

The thing is, that even though the String has the same length on both
sides, the decoded byte array is shorter then the original one.
I've tried a couple of different implementation on both sides, with
the same results.

What library are you using? Be aware that IE does not let you to read
binary files no matter what.
 
T

Tamir Weiss

In comp.lang.javascript message <[email protected]
glegroups.com>, Mon, 14 May 2007 10:10:44, Tamir Weiss



It is clear what your problem is; it is that you have done something
wrong.

A better description of what code you use might render possible a more
specific response. However, as you asked no question, you may not be
expecting any answer.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. [email protected] Turnpike v6.05 IE 6
FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

The encoding in JavaScript is done using the webtoolkit.base64 encoder
(on FireFox, but I'd imagine it would work on both).
The decoding is done using the org.apache.commons.codec library.

I'm not using any special parameters on neither sides, so I didn't
want to give any meaningless details.
I'm pretty new to all the javascript and base64 thing, so I'm
suspecting something in my HTML\Servlet is misconfigured.

If you've seen something like that, please tell me what helped you.
 
J

Julian Turner

I'm trying to send a byte array (JPG image) from javascript to a
servlet for processing.
I'm using Base64 to encode the byte array in javascript, and then a
base64 decoder in the servlet to decode it.

The thing is, that even though the String has the same length on both
sides, the decoded byte array is shorter then the original one.
I've tried a couple of different implementation on both sides, with
the same results.

Hi

I don't think you have provided enough information for the question to
be answered.

1. JavaScript does not have a "byte" value, so what do you mean by
"byte array"? Do you mean a JavaScript "Array" of JavaScript
"Number"?

2. How did you manage to load a JPG image into a JavaScript Array in
the first place?

What method did you use? I.e. are you sure that you really did manage
to get a JPG into a JavaScript Array of Numbers without any error?

It is possible to load binary in JavaScript, provided the client
browser has the necessary security permissions. Microsoft have a
number of Active X objects, such as ADODB.Stream and
Scripting.FileSystemObject . It is possible to use
Scripting.FileSystemObject to read binary files, contrary to popular
opinion, but it is a little tricky, and it requires a knowledge of
Windows code pages and the difference between the TextStream.Read and
ReadAll methods.

3. How are you sending the encoded Base64 to the servlet?

4. You may wish to test whether webtoolkit's base64 encoder is
actually working properly.

Julian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top