|
|
|
|
|
|
|
|
Label dropArea = new Label("Drop files here"); |
|
|
Label dropArea = new Label("Drop files here"); |
|
|
FileDropTarget<Label> dropTarget = new FileDropTarget<>(dropArea, event -> { |
|
|
FileDropTarget<Label> dropTarget = new FileDropTarget<>(dropArea, event -> { |
|
|
|
|
|
|
|
|
List<Html5File> files = event.getFiles(); |
|
|
|
|
|
|
|
|
Collection<Html5File> files = event.getFiles(); |
|
|
files.forEach(file -> { |
|
|
files.forEach(file -> { |
|
|
// Max 1 MB files are uploaded |
|
|
// Max 1 MB files are uploaded |
|
|
if (file.getFileSize() <= 1024 * 1024) { |
|
|
if (file.getFileSize() <= 1024 * 1024) { |
|
|
|
|
|
|
|
|
// Output stream to write the file to |
|
|
// Output stream to write the file to |
|
|
@Override |
|
|
@Override |
|
|
public OutputStream getOutputStream() { |
|
|
public OutputStream getOutputStream() { |
|
|
return new FileOutputStream("/path/to/files/" |
|
|
|
|
|
+ file.getFileName()); |
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
return new FileOutputStream("/path/to/files/" |
|
|
|
|
|
+ file.getFileName()); |
|
|
|
|
|
}catch (FileNotFoundException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Returns whether onProgress() is called during upload |
|
|
// Returns whether onProgress() is called during upload |
|
|
|
|
|
|
|
|
Notification.show("Stream failed, fileName=" |
|
|
Notification.show("Stream failed, fileName=" |
|
|
+ event.getFileName()); |
|
|
+ event.getFileName()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean isInterrupted() { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |