aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes JQuery for file upload related functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JQuery for file upload related functionality" Watch "JQuery for file upload related functionality" New topic
Author

JQuery for file upload related functionality

Maya Raman
Greenhorn

Joined: Mar 05, 2007
Posts: 10
Hello, I am usually a server side programmer, but now I have a need to get a list of files from one specific folder on the client (where the browser runs). I have been trying to use JQuery file upload feature, and while it works, and does open a miniature Explorer feature, it is just overkill for me, and I don't know how to get what I want from it. Is there an easier way for me to specify a folder name and get a list of files that are present in the folder?

I have also tried to look at Apache HttpClient, but there is just so much unknown stuff there for me to learn, that my head hurts from trying to do, what is possibly a rather simple thing to do.

Any help is much appreciated. Thanks!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Just to be clear: are you saying that you want to have something which runs in a browser and, without the user's agreement, takes a file from the machine where the browser is running and uploads it to your server?

This sounds to me like a serious violation of security, and so I wouldn't expect you could do that from a component which the user hasn't been asked to accept as secure (such as your Javascript code).
Maya Raman
Greenhorn

Joined: Mar 05, 2007
Posts: 10
Actually no, I do not want to upload the file (at least not in this case). I just want to display a list of files from say, C:\Test, back to the user in a listbox.

It is very similar to the first step of file upload on a mail client... but instead of showing the user the entire file explorer, I want to restrict it to one folder (and one file type).

Also wanted to add that this is a secure application meant for a closed audience, over the intranet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

What jQuery feature are you talking about? JavaScript has no access to the client file system, so I'm not sure what feature you are talking about, unless there's some plugin that cooperates with an IE ActiveX control?

And, please check your private messages for an important administrative matter. Thanks.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Maya Raman
Greenhorn

Joined: Mar 05, 2007
Posts: 10
The JQuery file upload is what I have now.

Oh, I see how my language could have been misleading. I do not want the list of files, but rather a list of file names, and these filenames will be displayed to the user where he/she would pick one.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, it seems to me that the jQuery file upload component already does all the things you asked for in your original post. The only thing it might not do is to start in a specific directory.

Here's a link to a page which tells you how to use the component: How to use only the Basic plugin (minimal setup guide) -- although I expect you should have seen that page already. At the bottom are links to the API and options for the component.

Perhaps you've seen those already as well. I don't see anything in them where you specify the starting directory, but I don't really find that surprising because generally Javascript code shouldn't know about directories on the client anyway.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

Yes, that's a plugin -- not part of the jQuery core. That's important to point out because plugins can be written by anybody, and are not guaranteed to be robust unless tsted and endorsed by the core group. (Though in this case, the plugin looks pretty good.)

[Edit: As customary, Paul snuck his post in before mine.]

In any case, what you are asking for appears to be exactly what the plugin demo is doing. Is that not what you are after?
Maya Raman
Greenhorn

Joined: Mar 05, 2007
Posts: 10
Thanks Paul. I have already seen those links and have been playing with them for some time now. There are two big problems - the look and feel is not at all what I need, and plus there isn't a way to specify a start folder, file types etc.
And so, it is taking me for too long, which is why I thought maybe there is an easier way to do this. I do not know much about HttpClient - can that help me do what I need to do?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

Maya Raman wrote:Thanks Paul. I have already seen those links and have been playing with them for some time now. There are two big problems - the look and feel is not at all what I need

That is just likely a matter of CSS.

and plus there isn't a way to specify a start folder

There won't be. As has already been pointed out twice, JavaScript has no access to the file system directly. The file system in only available via the HTML file input, and it doesn't give us that ability.

file types etc.

The plugin does allow you to specify the legal file types. That doesn't prevent anyone from picking them in the file browser, but if an illegal file is chosen, it's not allowed to be uploaded. That's about the best that can be done given the limitations imposed by the browser.

I do not know much about HttpClient - can that help me do what I need to do?

No. It has nothing at all to do with all of this. That's like asking if a spoon will help you climb a tree.
Maya Raman
Greenhorn

Joined: Mar 05, 2007
Posts: 10

That's like asking if a spoon will help you climb a tree.


I had no idea I was so off the mark. Guess I got confused by reading somewhere about HttpClient and FileUploads...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Yes, HttpClient is an Apache project which simplifies the process of accessing web sites from Java code. So being written in Java, it wouldn't be useful in a Javascript environment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JQuery for file upload related functionality