image upload refactoring