Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Guan - 24 Oct 2006 03:41 GMT
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 :)
Manish Pandit - 24 Oct 2006 08:17 GMT
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 - 24 Oct 2006 09:44 GMT
Hi Manish,

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

> Hi,
>
[quoted text clipped - 7 lines]
> -cheers,
> Manish
Guan - 26 Oct 2006 05:58 GMT
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

> Hi,
>
[quoted text clipped - 7 lines]
> -cheers,
> Manish
Manish Pandit - 26 Oct 2006 06:10 GMT
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 - 04 Nov 2006 07:16 GMT
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

> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.