View Full Version : binay data upload
tamirw
19 May 2007, 11:22 PM
I'm pretty new to this, so I apologize in advance if you've heard my question in the past (though I couldn't find any answer in the forums).
I'm looking for way to asynchronously upload an image to my servlet. I'm not talking about uploading a file (I've seen many examples for this), but just uploading the byte array the the JPEG image consists of. The byte array itself comes from a Flash object I've developed.
I tried converting the Byte array into a Base64 String, but then I ran into problem decoding it propery on the server side (did I mention I'm using a servlet ?). That's why I think the best solution for me would be to get the binary data through the request.getInputStream() on the server.
If you can help me achieve this, or if you have different approaches for a solution, please share them with me.
Thanks,
Tamir
Animal
20 May 2007, 3:30 AM
Wrong forum.
But why are you converting to a base64 String? Just read the bytes from the InputStream, and save them to a FileOutputStream unchanged.
tamirw
20 May 2007, 3:55 AM
What's the right forum ?
I wish I could do that, if I only know how to POST my byte-array to the server ...
i have onyl basic Flash knowledge but as far as i recall it is possible to do "ajax" (would be afax in this case ;) ) calls directly with Flash. No need to pass the data to JavaScript.
As Animal pointed out, there shouldn't be the need to convert your data to Base64 - HTTP can handle 8-Bit and non-ASCII chars in the data block.
You should probably ask your question at a Flash Forum or Java Servlet Forum, because i don't think that's really an Ext issue.
Animal
20 May 2007, 4:10 AM
Perhaps forums.java.sun.com
So, you have your byte array in your servlet, and you need to post it on again to yet another server?
tamirw
20 May 2007, 4:20 AM
It could be my lame English, but I don't think I explained myself very well.
I have my byte array in the HTML\JavaScript, not in my sevlet.
I know I can issue an Element.load() call, that would activate a doPost method on my servlet, but I don't know how to pass the byte-array TO my servlet.
That's the core of my question : how can I send a byte array as a parameter to a POST request ?
(I'm sorry if I'm wasting everyone's time here :))
Your byte-array is only a string - or can be converted into one. Pass that string as value of a parameter. You probably want to use Ext.data.Connection for the Ajax call: http://extjs.com/deploy/ext/docs/index.html#http://extjs.com/deploy/ext/docs/output/Ext.data.Connection.html
But I don't think you will be happy with that when your image is big (= some KBs and above). If your data comes from a Flash object you developed, why not alter that Flash object to directly send the Image from the Flash object to your servlet? IMHO, you really should consider this.
tamirw
21 May 2007, 2:53 AM
I've found out what was hurting my Base64 in the first place !
Turns out I had a few plus signs ('+') in my encoded String, that got replaced to blanks (' ') somewhere between my client and my server. That obviously changed the decoded byte-array, and hence the transfered Object.
Thanks for all your help !
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.