Flow of the request is shown in image above.
When the file is being uploaded it is results in 502 Bad Gateway. But when IP address of source is bypassed at WAF level file is getting uploaded successfully. No event is getting generated at WAF which could have indicated why it is not getting uploaded.
Bypassing the IP is making the request successful. But it is not solving the problem because the moment IP changes it results in the same error.