Open Yuniac opened 10 months ago
This is still broken, I degraded the library to 1.9.0
and used this solution : https://github.com/dmitriy-nz/nestjs-form-data/issues/47#issuecomment-1710264360
This is the only thing that works
@Yuniac Hi, I am trying to reproduce your issue but it is not reproducible. Automatic tests will not allow you to certify a version with obvious behavioral errors. Please provide more details about your environment, nest version, nodejs, controller. Or create a small repository where the issue is reproduced. Here is my environment where I tried:
package.json
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"nestjs-form-data": "^1.9.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
app.controller.ts
import {
Body,
Controller,
HttpCode,
HttpStatus,
Post,
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { ImagePostDto } from './ImagePostDto';
import { FileSystemStoredFile, FormDataRequest } from 'nestjs-form-data';
@Controller()
export class AppController {
@Post('files')
@UsePipes(new ValidationPipe({ transform: true }))
@FormDataRequest({ storage: FileSystemStoredFile })
@HttpCode(HttpStatus.OK)
getHello(@Body() body: ImagePostDto): any {
console.log(body);
return body;
}
}
ImagePostDto.ts
import {
FileSystemStoredFile,
HasMimeType,
IsFiles,
MaxFileSize,
} from 'nestjs-form-data';
export class ImagePostDto {
@IsFiles({ each: true })
@MaxFileSize(1e7, {
each: true,
message: 'The maximum size for a file is 10mb',
})
@HasMimeType(['image/png', 'image/jpeg'], {
each: true,
message: (e) => {
return `Error message`;
},
})
files: FileSystemStoredFile[];
}
Request & response:
Hi everyone, thanks for your feedback This issue should be also fixed in the version 1.9.9, please try it out https://github.com/dmitriy-nz/nestjs-form-data/issues/60#issuecomment-2184924859 @Yuniac
Hello. Thanks for creating this library.
A while ago, I had an issue where files sent as an array weren't appropriately received on the server and to fix this I used this hack from another issue that was opened about this: https://github.com/dmitriy-nz/nestjs-form-data/issues/47#issuecomment-1710264360
Now, when using version
1.9.1
I can't send an array of files, the validation always fails for the size and type of the files. It would only work if I send one file. Please how can I solve this? I have used the code from the readme even to see if it would work but it still doesn't work.DTO:
And I tried to send both via Postman and via my code, neither would work:
Code:
PostMan:
And this is the error I get:
Here are the images that I'm sending from the request body log:
Thanks in advance. I appreciate any further guidance on those to properly use your library