Skip to content

Add support for media types #216

@marcuscfarias

Description

@marcuscfarias

Hey, i would like to ask the support for media types, because I am uploading an image and the documentation doesnt follow the fluentvalidation rules. Check it below:

internal static class UploadProductImageConsts
{
    public const long MaxSizeBytes = 2 * 1024 * 1024;

    public static readonly string[] AllowedContentTypes = ["image/jpeg", "image/png"];
}

internal sealed class UploadProductImageRequestValidator : AbstractValidator<UploadProductImageRequest>
{
    public UploadProductImageRequestValidator()
    {
        RuleFor(x => x.File)
            .NotNull();

        RuleFor(x => x.File.Length)
            .GreaterThan(0)
            .LessThanOrEqualTo(UploadProductImageConsts.MaxSizeBytes)
            .When(x => x.File is not null);

        RuleFor(x => x.File.ContentType)
            .Must(UploadProductImageConsts.AllowedContentTypes.Contains)
            .When(x => x.File is not null);
    }
}
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions