How to avoid 504 Gateway Time-out errors with REST when uploading large files?

I am uploading a video file that is just about 1.5GB.  I am uploading the file via the csf/temporary endpoint, in 20 m-byte chunks.

The file uploads fine, no errors.  But when I create the Media object via the /media/{appid}/files endpoint, referencing the context ID of the video, and after some time I get a 504 "Gateway Time-out" error.

I thought perhaps that the server needed some time to reassemble the file (unloaded in 73 parts) before I called the Create Media endpoint, so I added a 2 minute pause between uploading the file and creating the Media object.  This did not help.

After some time I am able to check the site, and the Media object was created, even though there was a timeout error.

My assumption is that the timeout is coming from the server, because the server is returning a 504 code and my app has no set timeouts.

My question is, is there any way to avoid the timeout error?  My script need to get the return data from the Create Media endpoint and log it, so that I can be sure that the Media item was actually created.