Improved error handling for file upload