First there is a snippet using the bind functionality. var image : FileParamHolder = _ bind("widget", xhtml, "image" -> fileUpload(image = _) } Now write out: val wbos : ByteArrayOutputStream = build(image) val fout = new File(outputFilename) if (fout.exists()) { Log.error("Tried to overwrite existing file") return "Error: Filename already exists" } val foStream = new FileOutputStream(fout) foStream.write(wbos.toByteArray()) foStream.close() def build(image : FileParamHolder) : ByteArrayOutputStream = { val bout = new ByteArrayOutputStream() val zipout : ZipOutputStream = new ZipOutputStream(bout) zipout.setMethod(ZipOutputStream.DEFLATED); zipout.setLevel(Deflater.DEFAULT_COMPRESSION); writeImage(zos, image) } private def writeImage(zos: ZipOutputStream, image:FileParamHolder):Unit = { if (image.fileName == "") { Log.info("Provided image file is null") return } if (image.fileName.lastIndexOf("\\") != -1) //this is needed if upload is from a windows system zos.putNextEntry(new ZipEntry("res/" + image.fileName.substring (image.fileName.lastIndexOf("\\")+1))) else zos.putNextEntry(new ZipEntry("res/" + image.fileName)) zos.write(image.file, 0, image.file.length) //make here a loop on very large files zos.closeEntry() }