need only Content-Type: text/plain from the form submit using mutilpart/form data

Discussion in 'Java' started by Guan, Oct 24, 2006.

  1. Guan

    Guan Guest

    Hi All,

    I am trying to use NetComponents-1.3.8a to create a web based FTP
    upload and download.

    i am using enctype:multipart/form-data for form submission.

    To obtained the contain the following code is used,

    ServletInputStream inputLocal = request.getInputStream();
    inputLocalBuf = new DataInputStream(inputLocal);
    if (!ftp.storeFile("test.txt",inputLocalBuf))
    - - - - - - - - - -- - - -- - - -- - - - -- - - -- - - - - -- - - -
    -- - - - - -

    For additional inform,
    storefile method - storeFile(String, InputStream) where string will be
    the filename, inputstream will be data obtain from inputstream.

    This following is the output i obtained when i open the test.txt i
    uploaded.

    -----------------------------7d6762690786
    Content-Disposition: form-data; name="radio1"

    upload
    -----------------------------7d6762690786
    Content-Disposition: form-data; name="datafile"; filename="C:\Documents
    and Settings\Administrator\Desktop\test.txt"
    Content-Type: text/plain

    This is a test
    -----------------------------7d6762690786
    Content-Disposition: form-data; name="Submit"

    Submit
    -----------------------------7d6762690786--

    - -- - - - - -- - - -- - - - -- - - -- - - -- - - - - - - - - - -- - -
    - - -- - - - - -- - - - - - - -- - - - - - - - -
    Now my question are:

    1) I only need the content - "this is a test" in my test.txt
    2) i like to find out how obtain the filename i want from the
    multipart/form-data rather than i hardcode.

    Thanks in advance :)
     
    Guan, Oct 24, 2006
    #1
    1. Advertising

  2. Hi,

    Use Apache FileUpload API. That will get FileItem object(s) from the
    Multipart request, which should help you extract the file name and
    content. You can strip out the path information and get just the file
    name to store.

    http://jakarta.apache.org/commons/fileupload/

    -cheers,
    Manish
     
    Manish Pandit, Oct 24, 2006
    #2
    1. Advertising

  3. Guan

    Guan Guest

    Hi Manish,

    Thanks for the reply. i shall read thru the API recommended.

    Manish Pandit wrote:
    > Hi,
    >
    > Use Apache FileUpload API. That will get FileItem object(s) from the
    > Multipart request, which should help you extract the file name and
    > content. You can strip out the path information and get just the file
    > name to store.
    >
    > http://jakarta.apache.org/commons/fileupload/
    >
    > -cheers,
    > Manish
     
    Guan, Oct 24, 2006
    #3
  4. Guan

    Guan Guest

    Hi,

    i included the following code to my program just to test it out.
    However i encountered an error when running this line List items =
    upload.parseRequest(request); during compliation

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.util.List;
    import com.oroinc.net.ftp.*;
    import org.apache.commons.fileupload.FileUpload;
    import org.apache.commons.fileupload.DiskFileUpload;
    ...............
    ..............
    // first check if the upload request coming in is a multipart request
    boolean isMultipart = FileUpload.isMultipartContent(request);

    // parse this request by the handler
    DiskFileUpload upload = new DiskFileUpload();

    // this gives us a list of items from the request
    List items = upload.parseRequest(request);

    ------------------------------------------------------------------------------------------------------
    The error displayed in the Jcreator description :

    unreported exception
    org.apache.commons.fileupload.FileUploadException;must be caught or
    declared to be thrown


    Manish Pandit wrote:
    > Hi,
    >
    > Use Apache FileUpload API. That will get FileItem object(s) from the
    > Multipart request, which should help you extract the file name and
    > content. You can strip out the path information and get just the file
    > name to store.
    >
    > http://jakarta.apache.org/commons/fileupload/
    >
    > -cheers,
    > Manish
     
    Guan, Oct 26, 2006
    #4
  5. You need to catch the FileUploadException. If you are not familiar with
    Exception Handling in Java, I'd recommend reading some tutorials and
    understanding it.

    -cheers,
    Manish
     
    Manish Pandit, Oct 26, 2006
    #5
  6. Guan

    Guan Guest

    Hi Manish,

    Thanks for your help. I have completed the upload part.

    Is there any recommendation Class for the downloading of the file from
    the server?

    Thanks

    Manish Pandit wrote:
    > You need to catch the FileUploadException. If you are not familiar with
    > Exception Handling in Java, I'd recommend reading some tutorials and
    > understanding it.
    >
    > -cheers,
    > Manish
     
    Guan, Nov 4, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    50,027
    SkyUCHC
    Jun 9, 2010
  2. robert112
    Replies:
    1
    Views:
    2,884
    Sowmya J
    Jan 21, 2010
  3. gouree phatak via .NET 247

    Why do I see only plain text instead of treeview web control ?

    gouree phatak via .NET 247, Mar 7, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    153
    gouree phatak via .NET 247
    Mar 7, 2005
  4. Alfredo Agosti
    Replies:
    3
    Views:
    375
    Aaron Bertrand - MVP
    Sep 19, 2003
  5. Replies:
    5
    Views:
    189
Loading...

Share This Page