Best way to upload multiple files from a browser

2019-01-21 04:08发布

I'm working on a web application. There is one place where the user can upload files with the HTTP protocol. There is a choice between the classic HTML file upload control and a Java applet to upload the files.

The classic HTML file upload isn't great because you can only select one file at a time, and it's quite hard to get any progress indication during the actual upload (I finally got it using a timer refreshing a progress indicator with data fetched from the server via an AJAX call). The advantage: it's always working.

With the Java applet I can do more things: select multiple files at once (even a folder), compress the files, get a real progress bar, drag'n'drop files on the applet, etc...
BUT there are a few drawbacks:

  • it's a nightmare to get it to work properly on Mac Safari and Mac Firefox (Thanks Liveconnect)
  • the UI isn't exactly the native UI and some people notice that
  • the applet isn't as responsive as it should (could be my fault, but everything looks ok to me)
  • there are bugs in the Java UrlConnection class with HTTPS, so I use the Apache common HTTP client to do the actual HTTP upload. It's quite big a package and slows down the download of the .jar file
  • the Apache common HTTP client has sometimes trouble going through proxies
  • the Java runtime is quite big

I've been maintaining this Java applet for a while but now I'm fed up with all the drawbacks, and considering writing/buying a completely new component to upload theses files.

Question

If you had the following requirements:

  • upload multiple files easily from a browser, through HTTP or HTTPS
  • compress the files to reduce the upload time
  • upload should work on any platform, with native UI
  • must be able to upload huge files, up to 2gb at least
  • you have carte blanche on the technology

What technology/compontent would you use?


Edit :

  • Drag'n'Drop of files on the component would be a great plus.
  • It looks like there are a lot of issues related to bugs with the Flash Player (swfupload known issues). Proper Mac support and upload through proxies with authentication are options I can not do without. This would probably rule out all Flash-based options :-( .
  • I rule out all HTML/Javascript-only options because you can't select more than one file at a time with the classic HTML control. It's a pain to click n-times the "browse" button when you want to select multiple files in a folder.

10条回答
Bombasti
2楼-- · 2019-01-21 04:42

I've never used it with files of 2GB in size, but the YUI File Uploader worked pretty well on a previous project. You may also be interested in this jQuery Plugin.

That said, I still think the Java Applet is the way to go. I think you'll end up with less portability and UI issues than you expect and Drag/Drop works great. For the record, Box.net uses a Java Applet for their multi-file quick uploads.

查看更多
闹够了就滚
3楼-- · 2019-01-21 04:46

OK this is my take on this

I did some testing with swfupload, and I have my previous experience with Java, and my conclusion is that whatever technology is used there is no perfect solution to do uploads on the browser : you'll always end up with bugs when uploading huge files, going through proxies, with ssl, etc...

BUT :

  • a flash uploader (a la swfupload) is really lightweight, doesn't need authorization from the user and has a native interface which is REALLY cool, me thinks
  • a java uploader needs authorization but you can do whatever you want with the files selected by the user (aka compression if needed), and drag and drop works well. Be prepared for some epic bugs debuggin' though.
  • I didn't get a change to play with Silverlight as long as I'd like maybe that's the real answer, though the technology is still quite young so ... I'll edit this post if I get a chance to fiddle a bit with Silverlight

Thanks for all the answers !!

查看更多
祖国的老花朵
4楼-- · 2019-01-21 04:53

Easiest way of file upload in java is GOJFileUpload.jar library

Here is the gojfileupload library tutorial:

GOJFileUpload

They give two method

  • UploadFile(String filepath,ArrayList imagenames,HttpRequest request)
  • UploadFile(String filepath,ArrayList dataname,ArrayList imagenames,HttpRequest request)

They'll return you HashMap the all file name which you uploaded after uploading at your given destination folder.

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-21 04:55

You may check the Apache Commons FileUpload package. It allows you to upload multiple files, monitor the progress of the upload, and more. You can find more information here:

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

Good luck

查看更多
登录 后发表回答