The widespread use of UAVs in smart cities for tasks like traffic monitoring and environmental data collection creates significant privacy and security concerns due to the transmission of sensitive data. Traditional UAV-MEC systems with centralized data processing expose this data to risks like breaches and manipulation, potentially hindering the adoption of these valuable technologies. To address this critical challenge, we propose UBFL, a novel privacy-preserving federated learning mechanism that integrates blockchain technology for secure and efficient data sharing. Unlike traditional methods relying on differential privacy (DP), UBFL employs an adaptive nonlinear encryption function to safeguard the privacy of UAV model updates while maintaining data integrity and accuracy. This innovative approach enables rapid convergence, allowing the base station to efficiently identify and filter out severely compromised UAVs attempting to inject malicious data. Additionally, UBFL incorporates the Random Cut Forest (RCF) anomaly detection algorithm to actively identify and mitigate poisoning data attacks. Extensive comparative experiments on benchmark datasets CIFAR10 and Mnist demonstrably showcase UBFL’s effectiveness. Compared to DP-based methods, UBFL achieves accuracy (99.98%), precision (99.93%), recall (99.92%), and F-Score (99.92%) in privacy preservation while maintaining superior accuracy. Notably, under data pollution scenarios with varying attack sample rates (10%, 20%, and 30%), UBFL exhibits exceptional resilience, highlighting its robust capabilities in securing UAV gradients within MEC environments.