refactor file upload handle code.