Browse Source

Merge pull request #9690 from nocodb/nc-fix/upload-file-size-limit

fix: upload file size limit
pull/9680/head
Pranav C 2 months ago committed by GitHub
parent
commit
1053e6e7c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      packages/nc-gui/components/cell/attachment/utils.ts
  2. 4
      packages/nocodb/src/constants/index.ts
  3. 10
      packages/nocodb/src/modules/noco.module.ts
  4. 8
      packages/nocodb/src/services/utils.service.ts

2
packages/nc-gui/components/cell/attachment/utils.ts

@ -135,7 +135,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
} }
// verify file size // verify file size
if (file?.size && file.size > attachmentMeta.maxAttachmentSize * 1024 * 1024) { if (file?.size && file.size > attachmentMeta.maxAttachmentSize) {
message.error( message.error(
`The size of ${(file as File)?.name || (file as AttachmentReqType)?.fileName} exceeds the maximum file size ${ `The size of ${(file as File)?.name || (file as AttachmentReqType)?.fileName} exceeds the maximum file size ${
attachmentMeta.maxAttachmentSize attachmentMeta.maxAttachmentSize

4
packages/nocodb/src/constants/index.ts

@ -1,4 +1,8 @@
export const NC_LICENSE_KEY = 'nc-license-key'; export const NC_LICENSE_KEY = 'nc-license-key';
export const NC_APP_SETTINGS = 'nc-app-settings'; export const NC_APP_SETTINGS = 'nc-app-settings';
export const NC_NON_ATTACHMENT_FIELD_SIZE =
+process.env['NC_NON_ATTACHMENT_FIELD_SIZE'] || 10 * 1024 * 1024; // 10 MB
export const NC_ATTACHMENT_FIELD_SIZE = export const NC_ATTACHMENT_FIELD_SIZE =
+process.env['NC_ATTACHMENT_FIELD_SIZE'] || 20 * 1024 * 1024; // 20 MB +process.env['NC_ATTACHMENT_FIELD_SIZE'] || 20 * 1024 * 1024; // 20 MB
export const NC_MAX_ATTACHMENTS_ALLOWED =
+process.env['NC_MAX_ATTACHMENTS_ALLOWED'] || 10;

10
packages/nocodb/src/modules/noco.module.ts

@ -22,7 +22,11 @@ import { UsersController } from '~/controllers/users/users.controller';
import { UsersService } from '~/services/users/users.service'; import { UsersService } from '~/services/users/users.service';
/* Metas */ /* Metas */
import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants'; import {
NC_ATTACHMENT_FIELD_SIZE,
NC_MAX_ATTACHMENTS_ALLOWED,
NC_NON_ATTACHMENT_FIELD_SIZE,
} from '~/constants';
import { MetaService } from '~/meta/meta.service'; import { MetaService } from '~/meta/meta.service';
import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller'; import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller';
import { ApiTokensController } from '~/controllers/api-tokens.controller'; import { ApiTokensController } from '~/controllers/api-tokens.controller';
@ -132,7 +136,9 @@ export const nocoModuleMetadata = {
MulterModule.register({ MulterModule.register({
storage: multer.diskStorage({}), storage: multer.diskStorage({}),
limits: { limits: {
fieldSize: NC_ATTACHMENT_FIELD_SIZE, fieldSize: NC_NON_ATTACHMENT_FIELD_SIZE,
fileSize: NC_ATTACHMENT_FIELD_SIZE,
files: NC_MAX_ATTACHMENTS_ALLOWED,
}, },
}), }),
], ],

8
packages/nocodb/src/services/utils.service.ts

@ -8,7 +8,11 @@ import { useAgent } from 'request-filtering-agent';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import type { ErrorReportReqType } from 'nocodb-sdk'; import type { ErrorReportReqType } from 'nocodb-sdk';
import type { AppConfig, NcRequest } from '~/interface/config'; import type { AppConfig, NcRequest } from '~/interface/config';
import { NC_APP_SETTINGS, NC_ATTACHMENT_FIELD_SIZE } from '~/constants'; import {
NC_APP_SETTINGS,
NC_ATTACHMENT_FIELD_SIZE,
NC_MAX_ATTACHMENTS_ALLOWED,
} from '~/constants';
import SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2'; import SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Base, Store, User } from '~/models'; import { Base, Store, User } from '~/models';
@ -465,7 +469,7 @@ export class UtilsService {
ncSiteUrl: (param.req as any).ncSiteUrl, ncSiteUrl: (param.req as any).ncSiteUrl,
ee: Noco.isEE(), ee: Noco.isEE(),
ncAttachmentFieldSize: NC_ATTACHMENT_FIELD_SIZE, ncAttachmentFieldSize: NC_ATTACHMENT_FIELD_SIZE,
ncMaxAttachmentsAllowed: +(process.env.NC_MAX_ATTACHMENTS_ALLOWED || 10), ncMaxAttachmentsAllowed: NC_MAX_ATTACHMENTS_ALLOWED,
isCloud: process.env.NC_CLOUD === 'true', isCloud: process.env.NC_CLOUD === 'true',
automationLogLevel: process.env.NC_AUTOMATION_LOG_LEVEL || 'OFF', automationLogLevel: process.env.NC_AUTOMATION_LOG_LEVEL || 'OFF',
baseHostName: process.env.NC_BASE_HOST_NAME, baseHostName: process.env.NC_BASE_HOST_NAME,

Loading…
Cancel
Save