Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read wave file data from post data

Posted on 2004-09-18
3
Medium Priority
?
240 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you have come across a situation where you need to find some EDB mailbox recovery techniques, then here you will find the same. In this article, we will take you through three techniques using which you will be able to perform EDB recovery. You …
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

916 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