Closed Misir8 closed 2 years ago
I tried to reproduce the problem, everything works as expected, see screenshots. My DTO class
export class AttachmentDto {
@IsFile()
@IsOptional()
@MaxFileSize(5e6)
@HasMimeType(['image/jpeg', 'image/png', 'image/jpeg'])
readonly image?: MemoryStoredFile;
}
Send request with image field:
Request:
DTO instance in console:
Send request without image field:
DTO instance in console:
it is empty because there are no other fields
Maybe the problem is that you are sending null or any other value in the optional field, then the validator tries to check it. In order for the validator to skip this field, it should not exist in the dto that is sent from the client. Try to check the request through REST Client (postman or insomnia)
@dmitriy-nz Thank you very much. I tested only in the swagger ui and always got a validation error there.
You're welcome! Please check this if all is well close the issue :relaxed:
When updating an entity, I want to make an optional file update. If the user did not add a new file, then leave the old file, and if he added it, then add a new file.
But when I write in the Dto like this:
I get an error: