diff --git a/api-gateway/src/api/service/artifact.ts b/api-gateway/src/api/service/artifact.ts index cd936d83e4..c5e5e83839 100644 --- a/api-gateway/src/api/service/artifact.ts +++ b/api-gateway/src/api/service/artifact.ts @@ -187,7 +187,7 @@ export class ArtifactApi { async uploadArtifacts(@Req() req, @UploadedFiles() files): Promise { try { if (!files) { - throw new HttpException('There are no files to upload', HttpStatus.UNPROCESSABLE_ENTITY) + throw new HttpException('There are no files to upload', HttpStatus.BAD_REQUEST) } const owner = req.user.did; const parentId = req.params.parentId; diff --git a/api-gateway/src/helpers/interceptors/multipart.ts b/api-gateway/src/helpers/interceptors/multipart.ts index 1a57aa19e9..714894fcb4 100644 --- a/api-gateway/src/helpers/interceptors/multipart.ts +++ b/api-gateway/src/helpers/interceptors/multipart.ts @@ -15,24 +15,28 @@ export function AnyFilesInterceptor(options: MultipartOptions = {}): Type => { - const buffer: Buffer = await part.toBuffer() +export const getFileFromPart = async (part: MultipartFileFastify): Promise => { + const buffer: Buffer = await part.toBuffer(); + + const { byteLength: size } = buffer; + const { filename, mimetype, fieldname, encoding } = part; + + if (!size || !fieldname) { + return null; + } + return { buffer, - size: buffer.byteLength, - filename: part.filename, - mimetype: part.mimetype, - fieldname: part.fieldname, - encoding: part.encoding, - originalname: part.fieldname + size, + filename, + mimetype, + fieldname, + encoding, + originalname: fieldname, }; }; \ No newline at end of file