Using EF Core, How Do You Set the Maximum Size of a File Uploaded to a Property with Data Type of Byte[]

1.1k Views Asked by At

CONTRACT TABLE

[MaxLength(2000000)]
[Required, FileExtensions(Extensions = ".PDF"]
public byte[] Document { get; set; }

I want to limit the user to uploading a PDF file no greater than 2 MB in size. So, I used the MaxLength and FileExtension attributes. Despite adding MaxLength(2000000) the column in my Contract table has data type of Varbinary(Max). This implies a maximum size of 2^31 bytes. From what I understand SQL Server will allow me to specify a size between 1 and 8,000 bytes. After that, I have to settle for Varbinary(Max). Is this correct or does someone have a way that I can limit the File Size to 2MB? I would like this implemented on the SQL server side AND through my controller [MVC project]. The reason I want both protections is I want to prevent someone with direct access to the database from uploading a file that is too large. I also want to prevent a user of my website from uploading files that are too large.

0

There are 0 best solutions below