Solved

Read wave file data from post data

Posted on 2004-09-18
3
233 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
some methods private some are not 8 211
HTML5 vs JSP - REST based application development 4 1,065
spring example non maven 4 87
login form jsp example 2 25
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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