File Uploads
If you want to do file uploads, look at the code that is responsible for adding a profile picture in ControllerPostActions::processformEditConsultantProfile
The same pattern for dealing with form data in the previous chapter holds.
The only differences are that
- the value for the image file that is being passed in via withData is the entire contents of a file, as a bytestring:
withData \$ \fd@(EditUserProfileFormData fdContact fdBlurb fdlistAsC fdimagecontents)
- there is an IO action in the ServerPartT handler, which writes the file:
liftIO \$ writeFileForce avatarpath fdimagecontents
- enctype="multipart/form-data" in the form itself
In the above, the fdimagecontents variable contents the entire contents of an image file.
writeFileForce is just a wrapper over writeFile that creates necessary parent directories if they are missing.