file upload function Optimization