BinaryFileResponse fails on Azure when running under Nginx on Linux (but works correctly on Windows/IIS) #47059
Replies: 4 comments 24 replies
-
i can confirm this behavior. i have exactly the same issue. |
Beta Was this translation helpful? Give feedback.
-
The code does not look like Symfony 🤔 Anyways did you check if the request to the image includes a |
Beta Was this translation helpful? Give feedback.
-
Hi, I have the same problem with Symfony 5.4 on Azure App Service product using php 8.0 + nginx Could you help me? |
Beta Was this translation helpful? Give feedback.
-
While I can't drop a lot of details as the code is proprietary, we've seen this issue manifest in an existing codebase when jumping from Ubuntu 18.04 to 20.04 as part of an EOL upgrade. Symfony version 5.x running php 7.4 under a debian variant container. The container itself did not change in any meaningful way, the host running the container workloads was what was upgraded. Same situation, pulling a file to be served by a symfony server (no nginx) but we only got 8192 of the file (cutting off the top in our case). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Symfony version(s) affected
5.4, 6.0 and 6.1 confirmed, presumably others
Description
A fairly simple controller which picks form input, chooses image from the disk and then returns it to webbrowser. The code works absolutely perfectly on local development instance of Laravel (Windows 10) or Azure Windows-based PHP service, but corrupts data when deployed on Azure PHP App Service on Linux (under nginx).
How to reproduce
REPRODUCER
Possible Solution
The following fix works for me, but I do not fully understand the reason for the problem or possible implications, so would prefer someone with better in-depth knowledge to review prior to submitting pull request. The issue is in the following line:
to fix, I implemented the following - eg PHP native function stream_copy_to_stream is replaced with a custom function, which does (as far as I could tell) the same thing.
As people observed, this simple code does not support Ranges (so you need to disable it in headers). The buffer size is chosen randomly - we could have a lively argument of what it should be, but it does not materially changes the fix.
Additional Context
I attached two versions of the same image returned by the SAME code running under Windows IIS (correct) and Linux (nginx) (corrupted


)
In Laravel, the original code was
response()->file() and response->download() produce the same result - this is understandable as they only differ in headers
Beta Was this translation helpful? Give feedback.
All reactions