Project

General

Profile

drag & drop uploads

Added by yvan vander sanden about 8 years ago

Hello.

I'm new to this library, so first I want to say thanks. I like working with it already.

I'd like to add a drag & drop file upload box, as seen in many modern web applications. I've looked at the WFileUpload widget, but it does not seem to support that. I assume that I'm not the first to desire this feature, so perhaps someone can give me a few pointers about how to do that?

Thanks,

yvan


Replies (11)

RE: drag & drop uploads - Added by Koen Deforche about 8 years ago

Hey Ivan,

This is something we've been willing to integrate already for some time, but never got around actually implementing it.

Can you file a feature request for this?

Regards,

koen

RE: drag & drop uploads - Added by yvan vander sanden about 8 years ago

Thank you for the fast response, Koen.

I've just added a feature request.

Regards,

yvan

RE: drag & drop uploads - Added by Daniel McRobb over 7 years ago

Yvan, do you still need this?

I have a working implementation as of tonight. With the existing Wt facilities (WResource and friends) and a small amount of javascript, it was not very difficult. I'll clean it up and post it in a couple of weeks if it will prove useful. I don't consider it generic or production grade, but perhaps it'll be enough to provide what's needed for a Wt-worthy implementation. The javascript just adds a drop handler with setJavaScriptMember() and registers it with addEventListener via doJavaScript(). I also add an event listener for drop in the WApplication that prevents the browser's default (on the window element).

I haven't looked at adding this as a feature of WFileUpload.

Koen, forgive me for not knowing... is this the right place to post the code snippets or should I put it in the issue that Yvan opened? Or some other communication path?

Background... I'm using this in my new photo gallery software that will replace gallery3 on my personal web server. All Wt, at the moment it's about 8,000 lines of C and nearly ready to deploy for my personal use as version 1.0. IMHO it's a pretty small code base for the features. With some refactoring and removing dead code paths, I think it'll shrink to about 7,000 lines of code (not counting CSS). Only took me 3 months from scratch, in my spare time (a few nights per week). Thanks to Wt.

Daniel

RE: drag & drop uploads - Added by Mario Charest over 7 years ago

I'm interrested.

RE: drag & drop uploads - Added by Koen Deforche over 7 years ago

Hey,

Certainly yes. You can choose how to contribute, whatever is easier to you. For a feature that isn't straight forward such as this, we will probably rework it rather than simply integrating a patch.

A patch in a redmine issue or a pull request (in github) will both work.

And we are certainly interested in this!

Regards,

Koen

RE: drag & drop uploads - Added by Daniel McRobb over 7 years ago

OK, thanks Koen!

You might be surprised how straightforward it is. The Wt team already laid nearly all of the groundwork with WResource and Http::Request. It was almost trivial once I found useful examples of what was needed on the client side.

I'll summit a patch file when I have time to finish it and clean it up, it'll be within the next 2 weeks.

RE: drag & drop uploads - Added by Daniel McRobb over 7 years ago

Just an update...

My first pass had a DropUpload widget (inherits from WContainerWidget) that accepted the drops. While refactoring a bit, I started thinking it would be much nicer (and probably not very difficult) to just add some functionality to WWidget so that any WWidget can be a drop upload target. Akin to the existing acceptDrops(), we'd have acceptDropUploads(). Akin to dropEvent() we'd have dropUploadEvent(). I don't know if I'll get around to doing this, so it might just wind up being a suggestion for someone else. But I will try to structure what I've done to make it easier to copy what I've done into a WWidget implementation.

Daniel

RE: drag & drop uploads - Added by Daniel McRobb over 7 years ago

I put a tar file in the issue that Yvan opened (Feature #3141). 2 source files, 2 headers. Hopefully someone finds it useful. It won't compile as-is since it's using some things from elsewhere in my applications, but it should compile on UNIX hosts by just removing the Syslog stuff.

RE: drag & drop uploads - Added by Mario Charest over 7 years ago

Thanks for sharing your work.

RE: drag & drop uploads - Added by yvan vander sanden about 7 years ago

Hi Daniel.

Just noticed your answer just now. But I can certainly use this code. Thanks for sharing!

RE: drag & drop uploads - Added by Mark Petryk over 5 years ago

Is this code available somewhere? I'm interested in a drag-from-outlook to drop-in-wt for logging outlook emails. Is something like this possible, and would the code mentioned in this thread support something like that?

~mark

    (1-11/11)