views:

4701

answers:

12

I want to add gmail-like file upload functionality for one of my projects. Can anybody help me with this?

My application is built in vb.net.

I would appreciate any kind of help or guidance.

Thanks Mithil Deshmukh

+22  A: 

Check out SWFUpload, which is essentially a javascript api to flash's absolutely superior file upload handling capabilities. Best thing out there until the browsers finally catch up.

From link:

  • Upload multiple files at once by ctrl/shift-selecting in dialog
  • Javascript callbacks on all events
  • Get file information before upload starts
  • Style upload elements with XHTML and css
  • Display information while files are uploading using HTML
  • No page reloads necessary
  • Works on all platforms/browsers that has Flash support.
  • Degrades gracefully to normal HTML upload form if Flash or javascript is unavailable
  • Control filesize before upload starts
  • Only display chosen filetypes in dialog
  • Queue uploads, remove/add files before starting upload

Demos

----- iframe upload -----

To start, you want to have an iframe on your page. This is meant for server communication. You'll hide it later, but for now, keep it visible. Give that iframe a name attribute, like "uploader" or something.

Now, in your form, set the target to the iframe's name and the action to a script you have on the server that will accept a file upload (like a normal form with a file upload). Add a link inside that form with the text "Add File". Set that link to run a javascript function which will add a new input to the form. This can be done via the DOM, but I would recommend a javascript library like jquery.

Once the new file input is added to the form, set the blur event of that input to a javascript function that will submit the form and then check it periodically for output. Reading an iframe can be tricky, but it's possible.

Have your file upload script output a "Done." or a filename or something when the upload is complete.

Check it every second or so until there is content. Once you have content, kill your timer and replace the file input with the name of the file (or "File Uploaded") or whatever.

Hide your iframe with css.

enobrev
downvote? did I somehow not answer the question?
enobrev
Yeah, I don't know why they would - I gave you +1 myself...
Jason Bunting
While I haven't used it myself several of my coworkers say this works well for their projects
Laith
It wasn't the OP, it was I who down-voted.Heavily biased against flash.
Asmor
I can understand the bias against flash in many instances, but file upload is one instance where it actually makes sense. At least until the browsers provide a similar api.
enobrev
Why penalise someone for a perfectly legitimate answer, Asmor?
ceejayoz
Totaly agree with enobrev!
Daniel Silveira
People... votes are highly personal, everyone is entitled to vote like they want
Juan Manuel
+8  A: 

From YUI! (Yahoo User Interface), http://developer.yahoo.com/yui/uploader/

  1. Multiple file selection in a single "Open File" dialog.
  2. File extension filters to facilitate the user's selection.
  3. Progress tracking for file uploads.
  4. A range of file metadata: filename, size, date created, date modified, and author.
  5. A set of events dispatched on various aspects of the file upload process: file selection, upload progress, upload completion, etc.
  6. Inclusion of additional data in the file upload POST request.
  7. Faster file upload on broadband connections due to the modified SEND buffer size.
  8. Same-page server response upon completion of the file upload.

Totally Free

Daniel Silveira
This requires Flash in order to work, but is a viable solution.
Jason Bunting
I've voted you down since the YUI uploader still needs flash player to be installed.
Gustavo Carreno
I don't understand why that would amount to a downvote. the OP never specified that flash is not allowed.
enobrev
I don't know why you would downvote someone for this. Obviously the developer that decides to use a component requiring Flash should know this tool might limit those few users that don't have it installed and that they should provide an alternative in those cases, but otherwise this is a good answer
Jason Bunting
A: 

I'd like a little more clarification of "Gmail-like" file uploading.

do you mean how if it sits for a little bit, it automatically attaches it to a draft?

James Hall
I do think it would be a good idea if the OP clarified what about the GMail file upload he likes and is looking for....
Jason Bunting
A: 

What Gmail uses? Flash? IFrame?

Daniel Silveira
It's hard to tell. The only flash I've seen on gmail is called sound.swf. Their entire architecture is based on iframes, so I wouldn't doubt it if they use iframes for upload as well.
enobrev
They switched to flash about 1-2 months ago. At least in gmail.
Maiku Mori
A: 

What I meant by gmail like using iframes. In gmail there is no "attach" button once you select the file to be uploaded. There is just a link and once the file is selected we don't have to perform the added functionality of attaching the file. I hope I made it clear, if not please add your comment.

A: 

I found many code samples which does this..but those are in php. I am trying to implement the same in vb.net.

As long as you know how to accept a file upload in your favorite server-side language, the rest is done via javascript. When using an iframe, it works the same way as a normal form post with a multipart/form-data enctype.
enobrev
A: 

Gmail's code is difficult to find your way around, but if I had to guess, this is how it works:

  • When you click "attach another file", it inserts a regular input type file control. On IE, it may also programmatically trigger the click event on the "browse" button so the file dialog opens immediately (it doesn't do this on firefox, and I don't have IE handy, but I believe IE allows for this)
  • After you select a file, it detects the change event of the input control, and starts a timer.
  • When the timer triggers, it detaches the input element from the form, and adds it to a different form in a hidden iframe, placing a simple link in the main (visible) form. The hidden iframe is then submitted to upload the file. (It may also clone the input element, but I haven't tried whether this works.)
Joeri Sebrechts
A: 

You can use iFrames for this

Ahmad
+1  A: 

For a non-flash solution, you can use NeatUpload. I used it on an extensive project last year with a no-flash requirement. It's very easy to integrate into existing solutions. I thought it was a breeze to work with. Easier, in my limited experience, than working with SWFUpload in ASP.NET. Probably because NeatUpload is built just for ASP.NET.

CarmineSantini
+1  A: 

Are you talking about an upload without a full page postback? Take a look at http://www.phpletter.com/Demo/AjaxFileUpload-Demo/, which creates a hidden iframe, copies the input control, and uses the iframe to perform the post to get the file on the server.

If you're looking for the behavior where when the user clicks "attach file" and the file browsing dialog automatically pops up, that can be done via javscript but doesn't work in FireFox, which has the security precaution of requring the user to invoke the "Browse" button directly (rather than programmatically through script).

For the "automatic" upload, use javascript to attach to the "change" event for the "value" property of the the 'input' control so that the will perform when a file has been selected.

sunflowerpower
+4  A: 

Here is the gmail uploader clone. This is the exact clone of gmail uploader with some extra facilities. You can see the thumbnails of images after uploading, Drag the thumbnails to change the order and replace any thumbnail. It is done using jQuery. You can see the demo here. The source code is free to download in a single zip file.

I hope you can easily remove some code and get the desired thing. You may leave comments on the ABCoder blog if you need further help.

adnan
A: 

Hi

You may use Flickr Uploader clone instead.