Created separate function for image upload handling.