java - How to handle drag & drop upload of folders? -


i implementing upload functionality in vaadin web application uses drag & drop, in vaadin sampler example.

my code identical example code there. when trying code , linked example however, there 1 important difference: when dropping folder, code starts show progress spinner, never finishes. none of streamvariable callback methods ever called. no bytes ever uploaded. sample application nothing (user visible @ least).

i don't want user able upload folders, need able detect whether dropped "file" folder.

unfortunately, neither wrappertransferable nor html5file objects give me indication. i've come heuristics determine whether have file or folder: check mime type empty, check filesisze small, check there no dots in filename. none of these safe though.

how can detect , prevent attempted upload of folder?

here code (again, straight copy of linked vaadin example).

    public class attachmentdropbox extends draganddropwrapper implements drophandler {      private final progressbar progress;      public attachmentdropbox(component root, progressbar progress) {         super(root);         this.progress = progress;         progress.setindeterminate(true);         setdrophandler(this);     }      @override     public void drop(draganddropevent dropevent) {         // expecting html5 drag         if (!(dropevent.gettransferable() instanceof wrappertransferable)) {             return;         }          final wrappertransferable tr = (wrappertransferable) dropevent.gettransferable();         final html5file[] files = tr.getfiles();         if (files == null) {             return;         }          if (files.length != 1) {             notification.show("please upload single files only", notification.type.warning_message);             return;         }          html5file file = files[0];          if (file.getfilesize() > settings.getclientmaxattachmentsize()) {             notification.show(                     messageformat.format("file rejected. attachments may not exceed {0} in size.",                             fileutils.bytecounttodisplaysize(settings.getclientmaxattachmentsize())),                     notification.type.warning_message);             return;         }          final bytearrayoutputstream bas = new bytearrayoutputstream();         final streamvariable streamvariable = new streamvariable() {              @override             public outputstream getoutputstream() {                 return bas;             }              @override             public boolean listenprogress() {                 return false;             }              @override             public void onprogress(final streamingprogressevent event) {                 // not called             }              @override             public void streamingstarted(final streamingstartevent event) {                 log.info("upload started: " + event.getfilename());             }              @override             public void streamingfinished(final streamingendevent event) {                 progress.setvisible(false);                 log.info("upload finished: " + event.getfilename());             }              @override             public void streamingfailed(final streamingerrorevent event) {                 notification.show(                         messageformat.format("failed upload file: {0}",                                 stringutils.abbreviate(event.getexception().getmessage(), 100)),                         notification.type.error_message);                 log.error("failed upload file '{}'", event.getfilename(), event.getexception());                 progress.setvisible(false);             }              @override             public boolean isinterrupted() {                 return false;             }         };         file.setstreamvariable(streamvariable);          progress.setvisible(true);     }      @override     public acceptcriterion getacceptcriterion() {         return acceptall.get();     } } 

this problem has been fixed in vaadin 7.7.0

this corresponding change note:

folder upload not supported of browsers , can cause streamvariable methods not fire on configurations. fix tries detect , prevent uploading of folders.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -