Bookstack cannot handle 'large' files
Describe the Bug
Update related settings to allow large files in apache, php, bookstack Upload large file Upload fails
Steps to Reproduce
- Update related settings to allow large files in apache, php, bookstack
- bookstack FILE_UPLOAD_SIZE_LIMIT=4096
- apache LimitRequestBody 4294967296
- php memory_limit = 4096M post_max_size = 4096M upload_max_filesize = 4096M
phpinfo() validates the above settings are loaded.
-
Upload large file (This one is Content-Length 975151309)
-
Observe error: attachments/upload?uploaded_to=377 422 (Unprocessable Content)
I'm seeing that files that go over the apache max request size will result in attachments/upload?uploaded_to=377 net::ERR_CONNECTION_RESET 413 (Request Entity Too Large)
But If you're within the apache max request size, then you get the 422 error. Is bookstack throwing this? It's hard to tell, since bookstack doesn't seem to write any log files.
Expected Behaviour
Expected upload to be successful.
Screenshots or Additional Context
No response
Browser Details
No response
Exact BookStack Version
v25.02
Updates Since Originally posting the bug: I made a quick test.php that accepted any type of upload. I uploaded the exact same file with 'Content-Length 975151309' and the test upload returned 200 OK
It does seem to point to bookstack doing the rejection of: 422 (Unprocessable Content)
Hi @kobaz,
The status code indicates the request validation is failing (which just checks the page id is valid, and the file upload is a file within the set size limit).
Can you confirm the full exact output of running ls -alh bootstrap/cache from your BookStack install?
intellasoft-support {/opt/BookStack} root# ls -al bootstrap/cache/
total 40K
drwxr-xr-x 2 bookstack bookstack 4.0K Mar 13 14:56 .
drwxr-xr-x 3 bookstack bookstack 4.0K Oct 25 2023 ..
-rwxr-xr-x 1 bookstack bookstack 14 Oct 25 2023 .gitignore
-rwxr-xr-x 1 root root 802 Mar 13 14:56 packages.php
-rwxr-xr-x 1 root root 22K Mar 13 14:56 services.php
Okay, what's the output of running the below from your BookStack install directory?:
php artisan tinker --execute="dd(config('app.upload_limit'))"
# php artisan tinker --execute="dd(config('app.upload_limit'))"
"4096" // vendor/psy/psysh/src/ExecutionClosure.php(40) : eval()'d code:1
Strange... isn't it?
Hi @kobaz, Sorry, I needed some time to dig further into this. I've now done some testing with large files.
I created a 4GB random file, then tested uploading, tweaking any config one property at a time to test the resulting behaviour.
Overall, I ended up with a scenario which allows upload/download of these files, and I set the following php.ini values along the way:
upload_max_filesize = 5G
post_max_size = 5G
memory_limit = 512M
During testing, I found that 422 status could be sent if BookStack could not read the upload as a file, which occured when the file exceeded the set upload_max_filesize in my case. A limited post_max_size may result in the same.
My guess is that in your scenario the php.ini values are not being applied as expected.
Often you may have multiple php.ini files on a system, so i've seen a few cases of the wrong one being edited and the changes not applying.
To check the exact php.ini files and options at play, you can create a phpinfo page within the BookStack setup.
Warning: This page can expose private environment info, so ideally only do this in a network-limited-access environment.
You can create this via running the below from your BookStack install:
echo "<?php phpinfo();" > public/info.php
Then go to <INSTANCE_URL>/info or <INSTANCE_URL>/info.php in the browser.
Then search for the php.ini options to see their actual values.
Towards the top of the page, it should tell you which php.ini files are in use.
Remember to delete this info page afterwards by deleting the public/info.php file within your BookStack install folder.
If you are running php via an FPM process (and are editing fpm specific config files) you will need to restart the php-fpm process for changes to take effect.