Hi.
Here is a really quick example of how it can work. It assumes your input field for multiple files is called "upload".
public Result upload(Context context) {
try {
for (FileItem fileItem : context.getParameterAsFileItems("upload")) {
String fileName = FilenameUtils.normalize(fileName);
File file = buildPath(fileName);
if (file.exists()) {
throw new BadRequestException("File already exist");
}
FileUtils.forceMkdirParent(file);
FileUtils.copyInputStreamToFile(stream, file);
// For logging purpose : FileUtils.byteCountToDisplaySize(file.length());
}
} catch (IOException e) {
throw new BadRequestException(e.getMessage(), e);
}
return Results.ok();
}
public String buildPath(String fileName) {
// TODO return the path where the file should be really stored
return null;
}