[frontend] Refactor some of the upload code.