Where do I get the Request-Object

Dear Friends,

I want to upload a file via HTTP multipart-formdata request (POST).

For that reason I use the FileUpload-API:

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

Everything is described perfectly and I am very happy that there is such a project!

But they didn't write how I could create a new Request-Object.

How do I do that?

Are there are different types of Request-Objects?

Here is my test-code so far:

publicclass FileUploader12{

List items =new ArrayList();

/** Creates a new instance of FileUploader12 */

public FileUploader12(){

// Create a factory for disk-based file items

FileItemFactory factory =new DiskFileItemFactory();

// Create a new file upload handler

ServletFileUpload upload =new ServletFileUpload(factory);

// Parse the request

Request request =new Request();

/*FileItem */ items = upload.parseRequest(request);

//Create a progress listener

ProgressListener progressListener =new ProgressListener(){

privatelong megaBytes = -1;

publicvoid update(long pBytesRead,long pContentLength,int pItems){

long mBytes = pBytesRead / 1000000;

if (megaBytes == mBytes){

return;

}

megaBytes = mBytes;

System.out.println("We are currently reading item " + pItems);

if (pContentLength == -1){

System.out.println("So far, " + pBytesRead +" bytes have been read.");

}else{

System.out.println("So far, " + pBytesRead +" of " + pContentLength

+" bytes have been read.");

}

}

};

}

}

Thank you very much!

With best Regards

MfG

Inno

[3096 byte] By [Innocentusa] at [2007-11-27 1:03:24]
# 1
As you see from the name, that code is designed to be run in a servlet. And in your servlet you have a doPost() method that passes you the request object as one of its parameters.
DrClapa at 2007-7-11 23:38:28 > top of Java-index,Java Essentials,Java Programming...
# 2
Well i completely agree with what my fellow poster have said u gonna use a servlet to implement it....where doXX() methods provide HttpServletRequest Object to youJust as an example checkout the example specified down
RahulSharnaa at 2007-7-11 23:38:28 > top of Java-index,Java Essentials,Java Programming...
# 3
Yes, please understand that commons-fileupload is intended to *receive* uploaded files on the server, NOT to upload the files *to* a server.If you want to perform a form post from Java code, you should use the commons-httpclient package:
Herko_ter_Horsta at 2007-7-11 23:38:28 > top of Java-index,Java Essentials,Java Programming...
# 4

Thank you!

That's it.

But how can I use the multipart-POST feature?

It is described in http://jakarta.apache.org/commons/httpclient/methods/multipartpost.html

But how can I use the subclasses?

Thank you all for your help!

With best regards

MfG

Inno

Innocentusa at 2007-7-11 23:38:28 > top of Java-index,Java Essentials,Java Programming...
# 5
Sample code is here: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/Look at MultipartFileUploadApp.java
Herko_ter_Horsta at 2007-7-11 23:38:28 > top of Java-index,Java Essentials,Java Programming...