upload.js: refactoring