Refactored file upload backend