Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read wave file data from post data

Posted on 2004-09-18
3
Medium Priority
?
238 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:manuel_m
ID: 12092630
0
 
LVL 6

Accepted Solution

by:
CodingExperts earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Shawn
IT teams define success as solving problems quickly. To enable ITSM modernization we have to think of adopting the tools and methods that will enable resolution of ITSM issues more quickly.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

730 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