optimized upload function