Hi
I have an applet that sends an audio stream via http Post.
I am able to create a text file and send text from the applet to it.
But when I toggle the code send tha audio the file gets created but only of 1 kb size and no data in it.
My code is as follows:
Test PHP code is:
<?PHP
if (isset($HTTP_POST_VARS['audioo']))
{
$filename ="file.au";
if (!$fp = fopen($filename, 'a')) {
exit;
}
if (!fwrite($fp, $HTTP_POST_VARS['audioo'] )) {
echo "failed";
} else {
echo "ok";
echo $HTTP_POST_VARS['audioo'];
}
fclose($fp);
exit;
} else {
$fp = fopen("failed.tst", 'a');
}
?>
Applet code:
URL url;
URLConnection con;
OutputStream oStream;
String parametersAsString;
byte[] parameterAsBytes;
String aLine;
parametersAsString = "audioo=";
parameterAsBytes = parametersAsString.getBytes();
int size = audioInputStream.available();
url = new URL("http","server", 80,"/abc/zyx.php");
con = url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content=length", String.valueOf(parameterAsBytes.length + size));
oStream = con.getOutputStream();
oStream.write(parameterAsBytes);
int retval =0;
ObjectOutputStream oos = new ObjectOutputStream(oStream);
AudioFormat audioFormat = audioInputStream.getFormat();
int bufferSize = (int) audioFormat.getSampleRate() * audioFormat.getFrameSize();
byte [] buffer = new byte[ bufferSize ];
int r = audioInputStream.read(buffer);
while(r!=-1) {
oos.write(buffer, 0, r);
r = audioInputStream.read(buffer);
}
oos.flush();
oStream.close();
The .au file gets created.
I am able to save a good audio file from the same output stream onto the local directory though.
Please assist.
Thank you
Regards
Manoj