Dynamic maximum file size in fileUploader widget

0
For a client requirement I'm looking for a method to allow an admin user changing the maximum file size allowed in run-time. The reason for this request is that occasionally large files need to be uploaded (200MB+), but generally for a user to upload this is not needed. Currently the widget supports a field to control the maximum allowed file size, but this is then hardcoded.Did anyone face a similar challenge, or perhaps have a solution?File Uploader | Mendix Documentation
asked
2 answers
0

Hi Jesper,


The standard File Uploader widget exposes Maximum File Size (MB) as a widget property, but its documentation does not provide a built-in way to bind that property to an attribute and change it dynamically at runtime.


For your requirement, I would consider the following approaches.


Option 1: Extend the File Uploader widget (recommended for a true runtime setting)

If an administrator must change the limit without redeploying the application:

  1. Create a copy or fork of the widget source, following its licensing and maintenance requirements.
  2. Add a dynamic configuration option that accepts an Integer attribute containing the maximum permitted size in MB.
  3. Read the configured value at runtime and use it to validate the selected file before upload.
  4. Refresh or retrieve the configuration when the administrator changes the setting.
  5. Add server-side validation as well, because client-side validation can be bypassed.

This requires custom widget development and testing; it is not a setting available out of the box.


Option 2: Use separate widget configurations for a small number of predefined limits

If the requirement is limited to a few known limits, you could configure separate uploader widgets with different maximum sizes and control their visibility based on the administrator's setting.

This is simpler, but it is not suitable for arbitrary limits because each widget's size remains statically configured.


Important: Check the platform upload limit

Even if the widget permits a file of 200 MB, the Mendix runtime or hosting platform may impose a lower request-size limit. The widget setting alone cannot override that restriction. Verify the supported limits for your deployment environment before implementing larger uploads.


Official references:


My recommendation: If the limit must be editable at runtime by an administrator, extend the widget to read a dynamic configuration value and validate the file on both the client and server. First confirm that your hosting platform supports the maximum size you intend to allow.


Hope this helps!

answered
0

Hi Jesper,

Looking at your screenshot, Maximum number of files and Maximum concurrent uploads already accept an expression (that’s the Edit... button), but Maximum file size (MB) is still a fixed number. So it can’t be bound to an attribute directly. There are two ways around it that work well, and you can combine them.

Option 1: Fully dynamic limit (admin can enter any value)

  1. Create a settings entity, for example AppSettings with an integer attribute MaxUploadSizeMB, and a small admin page to edit it.
  2. In the File Uploader, set Maximum file size to the absolute maximum you’d ever allow, for example 500.
  3. On the Advanced tab, set On upload success to a microflow. It runs once per uploaded file and receives the file as a parameter. In that microflow:
    • Retrieve your AppSettings object.
    • Decision: $UploadedFile/Size > $AppSettings/MaxUploadSizeMB * 1024 * 1024 (Size is in bytes)
    • If true, delete the file and show a message like “This file is larger than the allowed X MB.”

I tested this with the latest version of the File Uploader: files under the limit upload normally, and files over the limit are removed straight away with a warning. Since the limit comes from the database, the admin can change it at any time without redeploying.

The only downside is that the file is uploaded first and rejected afterwards. If you’re on an older version without On upload success, update the widget from the Marketplace, or do the same check in the microflow behind your Save button.

Option 2: Two uploaders with different limits (no wasted upload)

Put two File Uploader widgets on the page, one with a normal limit (for example 25 MB) and one with a large limit (for example 500 MB). Control which one is visible with a boolean such as AllowLargeUploads, which the admin can switch on when needed (or base it on a user role).

Here the widget itself rejects big files before they’re uploaded, but you’re limited to the fixed values you choose.

Combining both: use Option 2 so normal users never upload huge files, and Option 1 on the large uploader so the admin can still set the exact limit.

For 200MB+ files: also check that your hosting setup allows uploads that large, for example any reverse proxy or ingress limits if you’re on-premises or on Private Cloud. Otherwise the upload can fail before it reaches the app.

Since the other two limits already support expressions, it might also be worth posting an idea on the Mendix Ideas forum to make Maximum file size an expression as well.

If this helps, please mark it as the accepted answer.


answered