Factor our more helpers.

* db error handling
* validation error handling
* 404 handling
* getting images from POSTs.