Personal blog websites have been integrated with Cloudflare CDN, utilizing the CDN to cache images, videos, and other static resources. After the recent launch of the video upload and playback feature, some issues have been encountered.
Cloudflare CDN Request Body Size Limitation Issue Due to a bit of laziness, the video upload feature on the blog management backend was implemented with a very simple upload interface. After going live, it was found that the video uploads always failed, with the videos generally being around two to three hundred MB in size.
Initially, I suspected that the web framework used by the server-side code was limiting the size of the request body. However, local testing did not reveal this issue, so I could only suspect that it was either a limitation by Railway (the service is deployed using Railway.app) or by Cloudflare CDN.
After some trouble, it was discovered that it was indeed a Cloudflare limitation.
For free users, the maximum body size for a single request is 100mb, and for paid enterprise users, the maximum is only 500MB.
In fact, 100Mb is sufficient; large file uploads should use chunked uploading.
Cloudflare CDN Does Not Support HTTP Range Request Header Issue Previously, when uploading videos of two to three hundred MB, I noticed some stuttering during playback but didn’t pay much attention at first. Later, when uploading a 1GB video, it took a long time to play after the upload, and the video was unplayable.
I initially suspected that my code did not support the HTTP range, but local testing and online testing bypassing Cloudflare CDN showed that range requests were effective.
By adding logs, it was found that after the request passed through Cloudflare CDN, the Range request header was removed, and Cloudflare CDN did not carry the Range request header when requesting the source site.
Additionally, tests also revealed that even after Cloudflare CDN fetched the video from the source site, subsequent requests that hit the cache still did not support range requests, and the browser still needed to wait for the entire video to be downloaded before it could be played.
The solution can only be to give up CDN caching and acceleration, configure Cloudflare to only resolve DNS, bypass Cloudflare CDN, and request to go directly to the source site. However, the downside is the increased data usage and slower video loading.