Description & Source Code

This demo allows you to upload an image file and attach multiple files from your local computer to the server via Drag'n'Drop.

Users will see the drop areas become visible after dragging files into the browser.

	<style src="/widgets/file_handling/dropupload/style.css" />
	<div xmlns:h="native" apply="org.zkoss.bind.BindComposer"
		viewModel="@id('vm') @init('demo.file_handling.dropupload.UserProfileViewModel')">
		<div sclass="content">
			<div sclass="photo">
				<image id="img" content="@load(" width="100%" height="100%"/>
			<dropupload maxsize="50" detection="browser" anchor="${img}"
				content="Drag your photo here (max 50KB)" 
			<div sclass="personDetails">
				<tablelayout columns="2">
					<tablechildren>Susan C.</tablechildren>	
					<tablechildren>Birth Date:</tablechildren>	
					<tablechildren>[email protected]</tablechildren>	
		<groupbox title="Attachments: " open="true" sclass="attachments">
			<div id="target" sclass="dropzone" children="@load(vm.attachments)">
				<template name="children" var="attachment">
					<span sclass="attachment">
						<a iconSclass="z-icon-paperclip" label="@load(attachment)"/>
			<dropupload maxsize="1024" detection="browser" anchor="${target}"
				onUpload="@command('doUploadFiles', files=event.medias)"
				content="Drag your files here (max. 1MB) multiple allowed"/>
.photo { 
	border: 3px dashed #e6e6e6; 
	border-radius: 10px;
	width: 123px; 
	height: 123px;
	position: absolute; 
	overflow: hidden;

.content .personDetails  {
	padding-left: 133px;

.content .personDetails .z-label {
	line-height: 1.42em;

.z-dropupload {
	background-color: #f2f2f2;
	padding: 3px;

.z-dropupload > div{
	top: 50%;
	margin-top: -1em;
	height: 2em;
	position: absolute;
	text-align: center;
	color: #cccccc;

.attachments > .z-groupbox-header,
.attachments > .z-groupbox-content {
	border-color: #e6e6e6;
.attachments .z-groupbox-title-content {
	color: #4d4d4d;

.attachments .z-dropupload > div {
	width: 180px;
	padding: 0 330px;

.dropzone {
	min-height: 50px;
.attachment {
	display: inline-block;
	padding: 4px 7px;
	margin-bottom: 3px;
	background-color: #f0f0f8;
	border-radius: 4px; 
.attachment > a {
	text-decoration: none;
.attachment > a > i {
	margin-right: 8px;
package demo.file_handling.dropupload;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.util.Clients;

public class UserProfileViewModel {
	private Media photo;
	private List<String> attachments;
	public void init() throws IOException{
		attachments = new ArrayList<String>();
	public void doUploadPhoto(@BindingParam("photo") Media photo) {
		if (!photo.getContentType().startsWith("image/")) {
			Clients.showNotification("Please upload an image");
		} = photo;
	public void doUploadFiles(@BindingParam("files") Media[] files) {
		for (Media file : files) {

	public Media getPhoto() {
		return photo;

	public List<String> getAttachments() {
	    return attachments;