Solved

Read wave file data from post data

Posted on 2004-09-18
3
231 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
ID: 12092630
0
 
LVL 6

Accepted Solution

by:
CodingExperts earned 500 total points
ID: 12095162
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
ID: 12490782
Thanks manu :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now