Refactoring the Pagedown image upload code