Browse Source

fix: attachment upload api corrections

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 1 year ago
parent
commit
62e4ecdf00
  1. 1
      packages/nocodb-nest/src/middlewares/extract-project-id/extract-project-id.middleware.ts
  2. 27
      packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

1
packages/nocodb-nest/src/middlewares/extract-project-id/extract-project-id.middleware.ts

@ -190,7 +190,6 @@ export class ExtractProjectIdMiddleware implements NestMiddleware, CanActivate {
context.switchToHttp().getRequest(), context.switchToHttp().getRequest(),
context.switchToHttp().getResponse(), context.switchToHttp().getResponse(),
() => { () => {
console.log('next');
}, },
); );
return true; return true;

27
packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

@ -7,11 +7,14 @@ import {
Query, Query,
Request, Request,
Response, Response,
UploadedFiles,
UseInterceptors, UseInterceptors,
} from '@nestjs/common'; } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express'; import multer from 'multer';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express'
import { OrgUserRoles, ProjectRoles } from 'nocodb-sdk'; import { OrgUserRoles, ProjectRoles } from 'nocodb-sdk';
import path from 'path'; import path from 'path';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants'
import { NcError } from '../../helpers/catchError'; import { NcError } from '../../helpers/catchError';
import Noco from '../../Noco'; import Noco from '../../Noco';
import { MetaTable } from '../../utils/globals'; import { MetaTable } from '../../utils/globals';
@ -66,10 +69,26 @@ export class AttachmentsController {
// ] // ]
// ); // );
) )
@UseInterceptors(FileInterceptor('files')) @UseInterceptors(
async upload(@Request() req: any, @Query('path') path: string) {
FilesInterceptor('files[]', null,{
storage: multer.diskStorage({}),
// limits: {
// fieldSize: NC_ATTACHMENT_FIELD_SIZE,
// },
limits: {
fileSize: NC_ATTACHMENT_FIELD_SIZE,
},
}),
)
async upload(
@UploadedFiles() files: Array<any>,
@Body() body: any,
@Request() req: any,
@Query('path') path: string,
) {
const attachments = await this.attachmentsService.upload({ const attachments = await this.attachmentsService.upload({
files: (req as any).files, files: files,
path: req.query?.path as string, path: req.query?.path as string,
}); });

Loading…
Cancel
Save