File Upload

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
LVL 16
suprapto45Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

suprapto45Author Commented:
Oh yes,

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

David
0
CEHJCommented:
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
objectsCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

suprapto45Author Commented:
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
suprapto45Author Commented:
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
CEHJCommented:
You could use a POST request, but then you would have to zip them
0
suprapto45Author Commented:
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
CEHJCommented:
Well i was thinking more of having no form at all (if that's acceptable)
0
girionisCommented:
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
suprapto45Author Commented:
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
suprapto45Author Commented:
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
girionisCommented:
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
CEHJCommented:
0
suprapto45Author Commented:
That is interesting. Let me try that out CEHJ

David
0
suprapto45Author Commented:
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
suprapto45Author Commented:
>>"What would happen there as data is String?"
What should we do?

David
0
girionisCommented:
> 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
CEHJCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Correction:

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

should have been

Enumeration<FileInputStream> enum = Collections.enumeration(files);
0
CEHJCommented:
Another correction (i'm a bit tired ;-)):

that will concatenate the files. Just do a normal ZipFile and add entries
0
suprapto45Author Commented:
Thanks

I will have a try on it

David
0
suprapto45Author Commented:
Excellent. Thanks everyone. I think that I have grabbed the concept now ;).

David
0
CEHJCommented:
:-)
0
girionisCommented:
:)
0
objectsCommented:
Isn't that what I suggested oiriginally, what exactly did u decide to use?
0
suprapto45Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.