Image upload code optimization