Upload

Pippo has builtin support for upload. For a perfect running example see UploadDemo from pippo-demo module.

In what follows I will show you how simple it is to work with uploads.

publicstaticvoidmain(String[]args){Pippopippo=newPippo();Applicationapplication=pippo.getApplication();// the following two lines are optional application.setUploadLocation("upload");application.setMaximumUploadSize(100*1024);// 100kapplication.GET("/",routeContext->routeContext.render("upload"));application.POST("/upload",routeContext->{// retrieves the value for 'file' inputFileItemfile=routeContext.getRequest().getFile("file");try{// write to disk// file.write(file.getSubmittedFileName()); // write the file in application upload locationFileuploadedFile=newFile(file.getSubmittedFileName());file.write(uploadedFile);// send responserouteContext.send("Uploaded file to '"+uploadedFile+"'");}catch(IOExceptione){thrownewPippoRuntimeException(e);// to display the error stack as response}});pippo.start();}