Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce max upload size #4868

Merged
merged 5 commits into from Jun 15, 2023
Merged

Enforce max upload size #4868

merged 5 commits into from Jun 15, 2023

Conversation

davisagli
Copy link
Sponsor Member

Add a config setting maxFileUploadSize, and check it when files are selected for upload.

If anyone has an idea about how to do this in a more centralized way, please let me know!

@netlify
Copy link

netlify bot commented Jun 13, 2023

Deploy Preview for volto canceled.

Name Link
🔨 Latest commit 057f5a5
🔍 Latest deploy log https://app.netlify.com/sites/volto/deploys/6489320bb9fa1500098e95f0

@cypress
Copy link

cypress bot commented Jun 13, 2023

Passing run #5601 ↗︎

0 503 20 0 Flakiness 0

Details:

Aad German translation for fileTooLarge
Project: Volto Commit: 057f5a5f9e
Status: Passed Duration: 12:23 💡
Started: Jun 14, 2023 3:23 AM Ended: Jun 14, 2023 3:36 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

Copy link
Member

@ksuess ksuess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my two cents

Comment on lines +382 to +400
export const validateFileUploadSize = (file, intlFunc) => {
const isValid =
!config.settings.maxFileUploadSize ||
file.size <= config.settings.maxFileUploadSize;
if (!isValid) {
toast.error(
<Toast
error
title={intlFunc(messages.error)}
content={intlFunc(messages.fileTooLarge, {
limit: `${Math.floor(
config.settings.maxFileUploadSize / 1024 / 1024,
)}MB`,
})}
/>,
);
}
return isValid;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. May I suggest to distinguish between image files and other files.
  • Two limits: one for image files, one for other files
  1. I think limits should be attributes of the Plone instance, rather than frontend configuration. This info would be available with Use the @navroot and @site controlpanels to render the <title> and the logo #3537 (assuming that every website has a logo ;-) ) together with an enhancement of the site attributes and an enhancement of the restapi endpoint @site.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, if this is to be a frontend configuration, I think this setting should be overrideable per-block type too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, if this is to be a frontend configuration, I think this setting should be overrideable per-block type too.

Do you think this is necessary? I think restricting the upload size is just for preventing the users to upload big high resolution photos for small teaser images. It is unrelated to the actual scaling for rendering.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may want to restrict the file size in a given block, not only for images, but for files. Think on files that can be downloaded or whatever.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ksuess @erral My goal here is to implement a simple, optional catch-all limit on file uploads for the entire volto installation. I agree there are lots of possible use cases where limits with a more specific scope might be needed, but frankly, my client just wants one limit everywhere and I don't have time to implement all the complexity you are bringing up at the moment.

Fortunately, I think what I've implemented here is forward-compatible with adding more specific limits later, as people have time to work on it. I think the roadmap would look something like this:

  1. In the backend, add a way to specify a limit on a specific NamedBlobFile/NamedBlobImage field. If it's not specified, fall back to a sitewide limit from the registry. Expose the field-specific limit in the schema API service, and the sitewide limit in the site API service.
  2. Make the volto FileWidget use the limit from the schema when it is specified, otherwise fall back to the sitewide limit from the site service, otherwise fall back to the limit from config.settings.
  3. Add a block-level limit to blocks that accept file uploads without using the FileWidget. Use it if specified, otherwise fall back to site and global settings in the same way.

With that plan in mind, are you okay with adding what I have in this PR, as a first step?

@sneridagh sneridagh merged commit 2ddcdf2 into master Jun 15, 2023
55 checks passed
@sneridagh sneridagh deleted the limit-file-upload branch June 15, 2023 18:22
sneridagh pushed a commit that referenced this pull request Jun 15, 2023
Co-authored-by: Timo Stollenwerk <stollenwerk@kitconcept.com>
sneridagh added a commit that referenced this pull request Jun 15, 2023
Co-authored-by: David Glick <david@glicksoftware.com>
Co-authored-by: Timo Stollenwerk <stollenwerk@kitconcept.com>
sneridagh added a commit that referenced this pull request Jun 17, 2023
* master:
  Release 17.0.0-alpha.13
  Enforce max upload size (#4868)
  Fix and improve the `addStyling` helper (#4880)
  Release 17.0.0-alpha.12
  Fix regression in horizontal scroll in contents view, add it back (#4872)
  Configurable Container component from registry for some key route views. (#4871)
  Allow to deselect color in ColorPickerWidget. (#4839)
sneridagh added a commit that referenced this pull request Jun 25, 2023
* master:
  Release 17.0.0-alpha.14
  Linked headlines (#3540)
  Release notes for 16.20.8 16.21.0 16.21.1 (#4910)
  Spanish translation (#4896)
  Refactor Anontools (#4845)
  Update to plone-backend 6.0.5 (#4897)
  Release 17.0.0-alpha.13
  Enforce max upload size (#4868)
  Fix and improve the `addStyling` helper (#4880)
  Release 17.0.0-alpha.12
  Fix regression in horizontal scroll in contents view, add it back (#4872)
  Configurable Container component from registry for some key route views. (#4871)
  Allow to deselect color in ColorPickerWidget. (#4839)
  Release 17.0.0-alpha.11
  Pagination with router params (#4698)
  Release 17.0.0-alpha.10
  feat(slate): Add css identifier to slate style menu options (#4847)
  Update Brazilian Portuguese translations (Fixes #4853)
  Convert header class to function (#4767)
sneridagh added a commit that referenced this pull request Jun 26, 2023
* master: (29 commits)
  Remove anonymous function calls. Remove default exports from. (#4917)
  Release 17.0.0-alpha.14
  Linked headlines (#3540)
  Release notes for 16.20.8 16.21.0 16.21.1 (#4910)
  Spanish translation (#4896)
  Refactor Anontools (#4845)
  Update to plone-backend 6.0.5 (#4897)
  Release 17.0.0-alpha.13
  Enforce max upload size (#4868)
  Fix and improve the `addStyling` helper (#4880)
  Release 17.0.0-alpha.12
  Fix regression in horizontal scroll in contents view, add it back (#4872)
  Configurable Container component from registry for some key route views. (#4871)
  Allow to deselect color in ColorPickerWidget. (#4839)
  Release 17.0.0-alpha.11
  Pagination with router params (#4698)
  Release 17.0.0-alpha.10
  feat(slate): Add css identifier to slate style menu options (#4847)
  Update Brazilian Portuguese translations (Fixes #4853)
  Convert header class to function (#4767)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants