Skip to content

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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';
Expand Down Expand Up @@ -52,7 +53,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 = () => {
const config = getConfig();
const overrideMaxFileSizeMB = parseInt(config.OVERRIDE_UPLOAD_FILE_MAX_SIZE_IN_MB, 10);
return !isNaN(overrideMaxFileSizeMB) && overrideMaxFileSizeMB > 0
? overrideMaxFileSizeMB * 1024 * 1024
: DEFAULT_UPLOAD_FILE_MAX_SIZE;
};

export const COURSE_BLOCK_NAMES = ({
chapter: { id: 'chapter', name: 'Section' },
Expand Down
4 changes: 3 additions & 1 deletion src/files-and-videos/files-page/FilesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import { CheckboxFilter, Container } from '@openedx/paragon';
import Placeholder from '../../editors/Placeholder';
import { getUploadFileMaxSize } from '@src/constants';

import { RequestStatus } from '../../data/constants';
import { useModels, useModel } from '../../generic/model-store';
Expand Down Expand Up @@ -90,7 +91,8 @@ const FilesPage = ({
usageErrorMessages: errorMessages.usageMetrics,
fileType: 'file',
};
const maxFileSize = 20 * 1048576;

const maxFileSize = getUploadFileMaxSize();

const activeColumn = {
id: 'activeStatus',
Expand Down
9 changes: 5 additions & 4 deletions src/generic/modal-dropzone/ModalDropzone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FileUpload as FileUploadIcon } from '@openedx/paragon/icons';

import useModalDropzone from './useModalDropzone';
import messages from './messages';
import { UPLOAD_FILE_MAX_SIZE } from '../../constants';
import { getUploadFileMaxSize } from '@src/constants';

const ModalDropzone = ({
fileTypes,
Expand All @@ -30,7 +30,7 @@ const ModalDropzone = ({
onChange,
onSavingStatus,
onSelectFile,
maxSize = UPLOAD_FILE_MAX_SIZE,
maxSize,
}) => {
const {
intl,
Expand All @@ -46,9 +46,10 @@ const ModalDropzone = ({
onChange, onCancel, onClose, fileTypes, onSavingStatus, onSelectFile,
});


const invalidSizeMore = invalidFileSizeMore || intl.formatMessage(
messages.uploadImageDropzoneInvalidSizeMore,
{ maxSize: maxSize / (1000 * 1000) },
{ maxSize: (maxSize || getUploadFileMaxSize()) / (1024 * 1024) },
);

const inputComponent = previewUrl ? (
Expand Down Expand Up @@ -129,7 +130,7 @@ ModalDropzone.defaultProps = {
imageHelpText: '',
previewComponent: null,
imageDropzoneText: '',
maxSize: UPLOAD_FILE_MAX_SIZE,
maxSize: 'undefined',
invalidFileSizeMore: '',
onSelectFile: null,
};
Expand Down
6 changes: 3 additions & 3 deletions src/textbooks/textbook-form/TextbookForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import FormikControl from '../../generic/FormikControl';
import PromptIfDirty from '../../generic/prompt-if-dirty/PromptIfDirty';
import ModalDropzone from '../../generic/modal-dropzone/ModalDropzone';
import { useModel } from '../../generic/model-store';
import { UPLOAD_FILE_MAX_SIZE } from '../../constants';
import { getUploadFileMaxSize } from '@src/constants';
import textbookFormValidationSchema from './validations';
import messages from './messages';

Expand Down Expand Up @@ -171,7 +171,7 @@ const TextbookForm = ({
onSavingStatus={onSavingStatus}
invalidFileSizeMore={intl.formatMessage(
messages.uploadModalFileInvalidSizeText,
{ maxSize: UPLOAD_FILE_MAX_SIZE / (1000 * 1000) },
{ maxSize: getUploadFileMaxSize() / (1024 * 1024) },
)}
onSelectFile={setSelectedFile}
previewComponent={(
Expand All @@ -180,7 +180,7 @@ const TextbookForm = ({
<span className="modal-preview-text">{selectedFile}</span>
</div>
)}
maxSize={UPLOAD_FILE_MAX_SIZE}
maxSize={getUploadFileMaxSize()}
/>
<PromptIfDirty dirty={dirty} />
</>
Expand Down