-
Notifications
You must be signed in to change notification settings - Fork 196
Override upload file max size in mb #2370
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
Changes from all commits
0769b61
6706b67
7c43ce8
02e4da3
f0e0252
a19d1ab
8189209
574a34c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #################### | ||
| OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB | ||
| #################### | ||
| This document provides information related to overriding the maxFileSize values allowed when uploading files into the Studio. | ||
| Currently the override affects the following areas of the platform: | ||
|
|
||
| * ``Content -> Files``: This is the general location for files to be uploaded into Studio. | ||
| * ``Content -> Pages & Resources -> Textbooks``: This is the location specifically for uploading textbooks into a course. | ||
|
|
||
| In addition to overriding the value in ``openedx-lms-production-settings`` it is also necessary to modify Caddy's ``max_size`` handling in the ``request_body`` otherwise Caddy will fail to process your file submission(s). | ||
|
|
||
| The following Tutor plugin can be used as a template to configure the override value. | ||
| In the example provided, override_value = "1024" means 1024MB or equivalently 1GB. Replace this with your preferred value. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from tutor import hooks | ||
|
|
||
| # Instructions / info | ||
| # override_value is defined as a string so bad formats (incorrectly entered values) don't crash Python immediately | ||
| # User MUST enter only digits as a POSITIVE integer representing a value in MegaBytes (MB), e.g. "1024" for 1GB | ||
| # This adds the value to the MFE_Config API as well as the CaddyFile CMS block | ||
|
|
||
| override_value = "1024" | ||
|
|
||
| # --- Validation --- | ||
| try: | ||
| override_int = int(override_value) | ||
| if override_int <= 0: | ||
| raise ValueError | ||
| except ValueError: | ||
| raise ValueError( | ||
| f"Invalid override_value: {override_value}. " | ||
| "It must be a positive integer without units (e.g., 1048)." | ||
| ) | ||
|
|
||
| # --- Config patches --- | ||
| hooks.Filters.ENV_PATCHES.add_items([ | ||
| ( | ||
| "openedx-lms-production-settings", | ||
| f""" | ||
| MFE_CONFIG["OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB"] = "{override_int}" | ||
| """ | ||
| ), | ||
| ]) | ||
|
|
||
| hooks.Filters.ENV_PATCHES.add_item( | ||
| ( | ||
| "caddyfile-cms", | ||
| f""" | ||
| # Maximum asset upload size in CMS/Studio | ||
| handle /assets/* {{ | ||
| request_body {{ | ||
| max_size {override_int}MB | ||
| }} | ||
| }} | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| Assuming your plugin is named ``override_max_asset_upload_size.py``: | ||
|
|
||
| * activate your plugin: ``tutor plugins enable override_max_asset_upload_size`` | ||
| * restart your server instance: ``tutor local stop && tutor local start -d`` | ||
| * validation: open the ``Files & Uploads`` page and confirm that your new override value is displayed instead of the default 20MB limit | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import { getConfig } from '@edx/frontend-platform'; | ||
|
|
||
| export const DATE_FORMAT = 'MM/dd/yyyy'; | ||
| export const TIME_FORMAT = 'HH:mm'; | ||
| export const DATE_TIME_FORMAT = 'YYYY-MM-DDTHH:mm:ss\\Z'; | ||
|
|
@@ -52,7 +54,16 @@ export const DECODED_ROUTES = { | |
| ], | ||
| }; | ||
|
|
||
| export const UPLOAD_FILE_MAX_SIZE = 20 * 1024 * 1024; // 100mb | ||
| // FilesUpload page - Default max size: 20MB else use env override if exists and valid number | ||
| const DEFAULT_UPLOAD_FILE_MAX_SIZE = 20 * 1024 * 1024; // 20 MB | ||
|
|
||
| export const getUploadFileMaxSize = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this function should live in utils.tsx and not in constants.js? |
||
| const config = getConfig(); | ||
| const overrideMaxFileSizeMB = parseInt(config.OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB, 10); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting |
||
| return !Number.isNaN(overrideMaxFileSizeMB) && overrideMaxFileSizeMB > 0 | ||
| ? overrideMaxFileSizeMB * 1024 * 1024 | ||
| : DEFAULT_UPLOAD_FILE_MAX_SIZE; | ||
| }; | ||
|
|
||
| export const COURSE_BLOCK_NAMES = ({ | ||
| chapter: { id: 'chapter', name: 'Section' }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { mergeConfig } from '@edx/frontend-platform'; | ||
| import { getUploadFileMaxSize } from '@src/constants'; | ||
|
|
||
| const DEFAULT_MAX = 20 * 1024 * 1024; | ||
|
|
||
| describe('getUploadFileMaxSize()', () => { | ||
| afterEach(() => { | ||
| // Reset config after each test to avoid leaks | ||
| mergeConfig({}); | ||
| }); | ||
|
|
||
| it('returns the global default when no config value is set', () => { | ||
| expect(getUploadFileMaxSize()).toEqual(DEFAULT_MAX); | ||
| }); | ||
|
|
||
| it('returns OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB when set to a valid positive integer', () => { | ||
| mergeConfig({ OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB: 7 }); | ||
| expect(getUploadFileMaxSize()).toEqual(7 * 1024 * 1024); | ||
| }); | ||
|
|
||
| it('falls back to default when override is not a number', () => { | ||
| mergeConfig({ OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB: 'not-a-number' as any }); | ||
| expect(getUploadFileMaxSize()).toEqual(DEFAULT_MAX); | ||
| }); | ||
|
|
||
| it('falls back to default when override is 0', () => { | ||
| mergeConfig({ OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB: 0 }); | ||
| expect(getUploadFileMaxSize()).toEqual(DEFAULT_MAX); | ||
| }); | ||
|
|
||
| it('falls back to default when override is negative', () => { | ||
| mergeConfig({ OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB: -5 }); | ||
| expect(getUploadFileMaxSize()).toEqual(DEFAULT_MAX); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use the overheading in this project.
Docs if you want to know more about our style guide: https://docs.openedx.org/en/latest/documentors/references/quick_reference.html#documentation-syntax-reference