Solved

Read wave file data from post data

Posted on 2004-09-18
3
227 Views
Last Modified: 2010-04-01
Hello Experts,

I'm using TIdHttp from Indy (version 8) in C++ Builder to post some parameters AND wave file data to test.jsp.  The parameters and the wave file data are separated by \r\n.

So in C++ I make a string called sRequestData that looks like this:
"param1=blabla&param2=blabla&\r\n" + wave file data.

When I debug in C++ Builder I can only see something like "RIFFèO\x04" for the wave file data but the string has actually a much larger length (real size of the file).

On the jsp page I get the parameters without a problem, but the wave file data seems only 10 bytes long (RIFFèO\x04...).

CAN ANYONE HELP ME TELL A WAY TO SEND WAVE FILE DATA USING A HTTP POST AND WRITING THE DATA TO A WAVE FILE ON THE SERVER?

(please bear in mind that I'm also sending other params with the same post)

This is my JSP code:

                String sParameters = "";
      String sWaveFileData = "";
      int i;
      int iCounter;

      ServletInputStream sis = request.getInputStream();
       BufferedReader in = new BufferedReader( new InputStreamReader( sis));
      
      ////////////////////////////////////////////////////////////
      // read parameter bytes
      ////////////////////////////////////////////////////////////

      sParameters = in.readLine();

      byte[] bytes = sParameters.getBytes();

      i = bytes.length;
      out.println( "# parameter bytes: " + i);

      out.println( "Parameter bytes:" );
      
      for ( i = 0; i<bytes.length; i++)
      {
            out.print( bytes[i]);
      }

      ////////////////////////////////////////////////////////////
      // read wave file data
      ////////////////////////////////////////////////////////////

      iCounter = 0;

      for ( i = 0; i != -1; )
      {
            i = in.read();
            sWaveFileData += new Integer( i).toString();
            iCounter++;
      }

      out.println( sWaveFileData);
      out.println( "# wave file bytes: " + iCounter); //only 10!!!

      ////////////////////////////////////////////////////////////
      //write wave file data to file
      ////////////////////////////////////////////////////////////

      FileWriter fw = new FileWriter( "c:/vmtx.wav");
      BufferedWriter bw = new BufferedWriter( fw);
      bw.write( sWaveFileData);            
      bw.close();
0
Comment
Question by:_manu_
  • 2
3 Comments
 
LVL 6

Expert Comment

by:manuel_m
Comment Utility
0
 
LVL 6

Accepted Solution

by:
CodingExperts earned 500 total points
Comment Utility
Use the MultipartRequest class written by Jason Hunter under servlets.com.  Go here to download the jar: http://www.servlets.com/cos/cos-05Nov2002.zip

Put cos.jar in your classpath.  Then write a servlet that accepts the request as a MultipartRequest object and you will be able to pull out the uploaded files... There is lots of documentation on how to use these classes on the internet including here:  http://www.servlets.com/cos/index.html

This is exactly why I'm telling you not to use jspsmartupload.  What a pain in the butt.  I always thought it was a pain until I found the one I was telling you about above.  For MultipartRequest, you need only put "cos.jar" on the classpath.  Then you can handle the upload so easily:

1) Download the zip and put "cos.jar" on classpath

2) Create an HTML form with upload button in a file called "form.html":

<form action="test.jsp" method="post" enctype="multipart/form-data">
<input type=file name=testfile>
<input type=submit>
</form>

3) Create an empty directory in "c:/upload"

4) Make a file called "test.jsp", and put:

<%@ page import="com.oreilly.servlet.*" %>
<%
 MultipartRequest mp = new MultipartRequest(request, "c:/upload");
 out.println("DONE");
%>

5) The file should have been uploaded.  You can find more command on what you cando with the MultipartRequest here: http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html
0
 
LVL 6

Expert Comment

by:CodingExperts
Comment Utility
Thanks manu :-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now