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

G

Guan

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 :)
 
G

Guan

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
 
M

Manish Pandit

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
 
G

Guan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top