Separate image upload code to upload.js