?
Solved

File Upload

Posted on 2006-06-01
26
Medium Priority
?
336 Views
Last Modified: 2013-11-24
Hi,

I am using Tomcat 5.5. If my clients give me the list of files in his machine, is there any way we can upload the file to server (Tomcat 5.5)? Preferably, the uploading is in the same request. I will try to google it later on but I currently am too busy with other things.

If you can provide me with the URL, that would be good.

David
0
Comment
Question by:suprapto45
  • 12
  • 8
  • 4
  • +1
26 Comments
 
LVL 16

Author Comment

by:suprapto45
ID: 16814002
Oh yes,

We can't really use the fileupload component as the number of files are not fixed.

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16814011
You need to use an applet to upload several files at a time (unless you use multiple upload form elements)

http://www.jupload.biz/
0
 
LVL 92

Expert Comment

by:objects
ID: 16814673
you can't return mutltiple file in one request response
use a servlet that zips up the required files and returns the zip to th e the client.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:suprapto45
ID: 16814963
Sorry CEHJ and objects

I just returned to office. Basically, without the fileupload like <input type="file"..>, is there any other way we can put the file into request?

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16814968
I was looking at the possibility using XmlHttpRequest but no luck. Another option is using ADODB.Stream of Microsoft but I do not want to do that ;) - I think you all know why.

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16814971
You could use a POST request, but then you would have to zip them
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16814978
Thanks CEHJ,

>>"You could use a POST request"
but without using tbe <input type="file"..> within the <form></form>. Is it possible to send it to request by POST?

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16814986
Well i was thinking more of having no form at all (if that's acceptable)
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 400 total points
ID: 16814987
What you can do is to have an option somewhere in the web page that says "upload more files". On clicking this link you will create more <input type="file"> objects *dynamically* (using JavaScript) and the users will be able to upload as many files as they want. If you are using yahoo for e-mails take a look at their uploading functionality, you need the same.

It might sound hard if you are not a JavaScript expert but I can tell you is not that hard. I have done something similar in the past and it works like a charm.
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16814998
Hi CEHJ,

That is acceptable. But I still can't think of any way to put this *stream* of file to POST. Can you share your idea?

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16814999
Hi girionis,

Thanks for your comments. That is a good suggestion but I prefer to have a look at what I am discussing with CEHJ first. If that is not possible then I would go for your suggestion ;).

David
0
 
LVL 35

Expert Comment

by:girionis
ID: 16815010
Yeap, no problem. If you decide to go with my suggestion and you also want some help with the JavaScript let me know and I will do my best :)
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1600 total points
ID: 16815016
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16815021
That is interesting. Let me try that out CEHJ

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16815044
I am just getting a little *blur*

// data would be key1=value1
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");

If the value1 is supposed to be the *stream* of the file uploaded instead of String. What would happen there as data is String?

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16815048
>>"What would happen there as data is String?"
What should we do?

David
0
 
LVL 35

Expert Comment

by:girionis
ID: 16815064
> What would happen there as data is String?

It should be the same, just use one of the other methods that write the data as stream.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1600 total points
ID: 16815067
That's a good question. The answer is that POSTs don't *need* named parameters. You can just post the stream and read it in your servlet. You may like to try something like:

DeflaterOutputStream out = new DeflaterOutputStream(new BufferedOutputStream(conn.getOutputStream()));
List<FileInputStream> files = new ArrayList<FileInputStream>();
files.add(new FileInputStream("a.java"));
files.add(new FileInputStream("b.java"));
files.add(new FileInputStream("c.java"));
Enumeration<?> enum = Collections.enumeration(files);
SequenceInputStream in = new SequenceInputStream(enum);
// Now read from in and write to out
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16815069
Correction:

>>Enumeration<?> enum = Collections.enumeration(files);

should have been

Enumeration<FileInputStream> enum = Collections.enumeration(files);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16815074
Another correction (i'm a bit tired ;-)):

that will concatenate the files. Just do a normal ZipFile and add entries
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16815088
Thanks

I will have a try on it

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16815118
Excellent. Thanks everyone. I think that I have grabbed the concept now ;).

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16815125
:-)
0
 
LVL 35

Expert Comment

by:girionis
ID: 16815127
:)
0
 
LVL 92

Expert Comment

by:objects
ID: 16815410
Isn't that what I suggested oiriginally, what exactly did u decide to use?
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16830173
Sorry objects,

I just read my mail. Well, I decided to use the combination of FileUpload, HttpClient of the Jakarta Common as well as the suggestion of CEHJ. I have not yet implemented it as this project happens in the coming weeks. However, I may not use the zip as I was thinking of some other alternatives.

I have to say that all the concepts are here ;).

David
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 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