Catch uploads bigger than upload_max_filesize
knallcharge opened this issue ยท 10 comments
Question
I'm trying to catch an error when a user uploads a file bigger than upload_max_filesize, but the file just passes the upload (checkmark is shown in the frontend), not calling the configured onValidation-event and not actually saving the file.
I'm using dropzone and have configured two methods in my services.yaml (onUpload, onValidation) as described here https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_validator.md:
app.upload_listener:
class: App\EventListener\UploadListener
arguments: [ "@doctrine.orm.entity_manager","@security.token_storage" ]
tags:
- { name: kernel.event_listener, event: oneup_uploader.post_upload, method: onUpload }
- { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidation }
Both methods are called with a small file which is processed correctly. But when I upload a 14MB JPG (upload_max_filesize and post_max_size set to 2M), both methods are never called while the file is still being rejected.
I also added a custom error handler (as seen here: https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_error_handler.md) as I thought the error might show up there, but it is also never called when uploading a file that's too big.
The problem now is, that I never get a chance to catch the error and the user sees a checkmark in the frontend, thinking that everything's fine, but the file never gets saved and processed.
This is my config:
oneup_uploader:
mappings:
gallery:
namer: app.safe_uniqid_namer
frontend: dropzone
max_size: -1
error_handler: app.upload_error_handler
storage:
directory: "%app.path.uploads%"
Q | A |
---|---|
Version | 3.1.2 |
Do you have any call stack (Symfony debug toolbar) from the failing request?
Unfortunately not as the request is not failing (which is probably the core of the problem?).
I see this this after the upload in the dropzone-area, indicating "OK" to the user:
This is my toolbar (tried 3 times):
And the Response:
followed by 14MB data (from the uploaded file)
That's it, no error and no uploaded file while the user thinks everything went ok.
which version of Symfony and PHP are you using?
Thank you. Please give me some time to look into this ๐
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The problem persists, any news on this?
Not yet, I'm afraid.
Addition (in case that matters): the above behaviour is shown in a Windows environment (IIS) as well as XAMPP on Windows (can't test Linux).
Workaround as I had to get this working:
- set post_max_size to 128M
- set upload_max_filesize to 20MB
- set max_size in oneup_uploader.yaml to 5242880 (5MB)
That works as long as the uploaded size is below 20MB (an error is shown if it's above 5MB), so the issue only happens when the system-limit is exceeded. Still not a great solution (fingers crossed that nobody uploads something bigger than 20MB) but better than having users thinking their uploads are fine while they're not.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.