How do I post a .wav file from CS5 Flash, AS3 to a Java servlet?
Posted
by Muostar
on Stack Overflow
See other posts from Stack Overflow
or by Muostar
Published on 2010-05-20T18:04:41Z
Indexed on
2010/05/20
18:10 UTC
Read the original article
Hit count: 276
Hi,
I am trying to send a byteArray from my .fla to my running tomcat server integrated in Eclipse. From flash I am using the following code:
var loader:URLLoader = new URLLoader();
var header:URLRequestHeader = new URLRequestHeader("audio/wav", "application/octet-stream");
var request:URLRequest = new URLRequest("http://localhost:8080/pdp/Server?wav=" + tableID);
request.requestHeaders.push(header);
request.method = URLRequestMethod.POST;
request.data = file;//wav;
loader.load(request);
And my java servlet looks as follows:
try{
int readBytes = -1;
int lengthOfBuffer = request.getContentLength();
InputStream input = request.getInputStream();
byte[] buffer = new byte[lengthOfBuffer];
ByteArrayOutputStream output = new ByteArrayOutputStream(lengthOfBuffer);
while((readBytes = input.read(buffer, 0, lengthOfBuffer)) != -1) {
output.write(buffer, 0, readBytes);
}
byte[] finalOutput = output.toByteArray();
input.close();
FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath(""+"/temp/"+wav+".wav"));
fos.write(finalOutput);
fos.close();
When i run the flash .swf file and send the bytearray to the server, I receive following in the server's console window:: (loads of loads of Chinese symbols) May 20, 2010 7:04:57 PM org.apache.tomcat.util.http.Parameters processParameters WARNING: Parameters: Character decoding failed. Parameter '? (loads of loads of Chinese symbols) and then looping this for a long time. It is like I recieve the bytes but not encoding/decoding them correctly. What can I do?
© Stack Overflow or respective owner