Make a check of file size a baked-in client side validation

Created on 15 July 2015, over 9 years ago
Updated 22 January 2024, about 1 year ago

Problem/Motivation

Drupal's managed_file form #type allows files of any size to be sent to the server. A server-size limit exists, but the user is not informed of the issue until waiting for the possibly large file to be uploaded. Testing a file's size on the client prior to upload is totally doable in the majority of browsers currently in use, and it is possible to gracefully skip this check, falling back to the current behavior, on IE 8 and 9.

Proposed resolution

Make the following changes:

  • Determine the maximum allowed size for a given managed_file form element, including as configured on file field widgets, and include this amount as a data- attribute of the file input.
  • Add javascript to compare the size of files to this attribute, and prevent form submission if appropriate.

User interface changes

This implies a new validation error, originating in JavaScript, may be presented to the user. Its details would need to be worked out.

API changes

None anticipated

Data model changes

None anticipated

Beta phase evaluation

✨ Feature request
Status

Postponed

Version

11.0 πŸ”₯

Component
File systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mbaynton Minneapolis, US

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Patch Failed to Apply
  • πŸ‡ΈπŸ‡³Senegal diaodiallo

    Hi all,

    I am having this same issue with Drupal 10.2.0, when I upload a file which too large (150mb) than the maximum (10mb) nothing happen but was supposed to have error message that the file is larger than allowed. However a size like 15mb trigger the error message.

    Thanks for any helping idea.

  • Status changed to Needs review 15 days ago
  • πŸ‡ΊπŸ‡¦Ukraine oleksandr.s

    Hi, here is patch for Drupal version 10.3.1. Should work with 10x versions.
    Probably also works with 11x versions.

    Patch provides client side validation to check file size.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Fixes should be in MRs against 11.x

    Thanks

    Did not review.

  • Pipeline finished with Failed
    15 days ago
    Total: 87s
    #396931
  • πŸ‡ΊπŸ‡¦Ukraine oleksandr.s

    Thank you for advice, I've created issue fork and created MR.

    Also, updated a patch for version 10.3.1

  • Pipeline finished with Failed
    15 days ago
    Total: 87s
    #396939
  • Pipeline finished with Failed
    15 days ago
    Total: 87s
    #396944
  • Pipeline finished with Failed
    15 days ago
    Total: 92s
    #396949
  • Pipeline finished with Failed
    15 days ago
    Total: 86s
    #396955
  • Pipeline finished with Failed
    15 days ago
    Total: 96s
    #396963
  • Pipeline finished with Failed
    15 days ago
    Total: 93s
    #396965
  • Pipeline finished with Failed
    15 days ago
    Total: 88s
    #396976
  • Pipeline finished with Success
    15 days ago
    Total: 426s
    #396985
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Left comments on MR but tagging for test coverage

Production build 0.71.5 2024