refactor image upload