Using EF Core, How Do You Set the Maximum Size of a File Uploaded to a Property with Data Type of Byte[]
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.
model-view-controller attributes ef-core-2.0 maxlength varbinarymax
add a comment |
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.
model-view-controller attributes ef-core-2.0 maxlength varbinarymax
1
Possible duplicate of Can I set 2 MB for maximum size of varbinary?
– John Wu
Nov 14 '18 at 5:29
Thanks. This is helpful. I can now update the column in the table from accepting files larger than 2 MB. It sounds like there is no way then to set this limit using attributes? So, I will have to write code that checks the size of the file a user uploads through my website using client side Javascript?
– Deepak Sreedharan
Nov 14 '18 at 5:49
1
In commercial web sites it is common to have redundant validation. As a convenience to your users it is probably best to double check the length in the client itself, which will save a user from having to wait for the file to post before seeing the error telling him he just wasted his time. You might also want another check in the web server to prevent hackers from attempting to upload very large files to cause a DoS.
– John Wu
Nov 14 '18 at 6:38
add a comment |
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.
model-view-controller attributes ef-core-2.0 maxlength varbinarymax
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.
model-view-controller attributes ef-core-2.0 maxlength varbinarymax
model-view-controller attributes ef-core-2.0 maxlength varbinarymax
edited Nov 14 '18 at 5:48
Deepak Sreedharan
asked Nov 14 '18 at 5:15
Deepak SreedharanDeepak Sreedharan
83
83
1
Possible duplicate of Can I set 2 MB for maximum size of varbinary?
– John Wu
Nov 14 '18 at 5:29
Thanks. This is helpful. I can now update the column in the table from accepting files larger than 2 MB. It sounds like there is no way then to set this limit using attributes? So, I will have to write code that checks the size of the file a user uploads through my website using client side Javascript?
– Deepak Sreedharan
Nov 14 '18 at 5:49
1
In commercial web sites it is common to have redundant validation. As a convenience to your users it is probably best to double check the length in the client itself, which will save a user from having to wait for the file to post before seeing the error telling him he just wasted his time. You might also want another check in the web server to prevent hackers from attempting to upload very large files to cause a DoS.
– John Wu
Nov 14 '18 at 6:38
add a comment |
1
Possible duplicate of Can I set 2 MB for maximum size of varbinary?
– John Wu
Nov 14 '18 at 5:29
Thanks. This is helpful. I can now update the column in the table from accepting files larger than 2 MB. It sounds like there is no way then to set this limit using attributes? So, I will have to write code that checks the size of the file a user uploads through my website using client side Javascript?
– Deepak Sreedharan
Nov 14 '18 at 5:49
1
In commercial web sites it is common to have redundant validation. As a convenience to your users it is probably best to double check the length in the client itself, which will save a user from having to wait for the file to post before seeing the error telling him he just wasted his time. You might also want another check in the web server to prevent hackers from attempting to upload very large files to cause a DoS.
– John Wu
Nov 14 '18 at 6:38
1
1
Possible duplicate of Can I set 2 MB for maximum size of varbinary?
– John Wu
Nov 14 '18 at 5:29
Possible duplicate of Can I set 2 MB for maximum size of varbinary?
– John Wu
Nov 14 '18 at 5:29
Thanks. This is helpful. I can now update the column in the table from accepting files larger than 2 MB. It sounds like there is no way then to set this limit using attributes? So, I will have to write code that checks the size of the file a user uploads through my website using client side Javascript?
– Deepak Sreedharan
Nov 14 '18 at 5:49
Thanks. This is helpful. I can now update the column in the table from accepting files larger than 2 MB. It sounds like there is no way then to set this limit using attributes? So, I will have to write code that checks the size of the file a user uploads through my website using client side Javascript?
– Deepak Sreedharan
Nov 14 '18 at 5:49
1
1
In commercial web sites it is common to have redundant validation. As a convenience to your users it is probably best to double check the length in the client itself, which will save a user from having to wait for the file to post before seeing the error telling him he just wasted his time. You might also want another check in the web server to prevent hackers from attempting to upload very large files to cause a DoS.
– John Wu
Nov 14 '18 at 6:38
In commercial web sites it is common to have redundant validation. As a convenience to your users it is probably best to double check the length in the client itself, which will save a user from having to wait for the file to post before seeing the error telling him he just wasted his time. You might also want another check in the web server to prevent hackers from attempting to upload very large files to cause a DoS.
– John Wu
Nov 14 '18 at 6:38
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293585%2fusing-ef-core-how-do-you-set-the-maximum-size-of-a-file-uploaded-to-a-property%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293585%2fusing-ef-core-how-do-you-set-the-maximum-size-of-a-file-uploaded-to-a-property%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Can I set 2 MB for maximum size of varbinary?
– John Wu
Nov 14 '18 at 5:29
Thanks. This is helpful. I can now update the column in the table from accepting files larger than 2 MB. It sounds like there is no way then to set this limit using attributes? So, I will have to write code that checks the size of the file a user uploads through my website using client side Javascript?
– Deepak Sreedharan
Nov 14 '18 at 5:49
1
In commercial web sites it is common to have redundant validation. As a convenience to your users it is probably best to double check the length in the client itself, which will save a user from having to wait for the file to post before seeing the error telling him he just wasted his time. You might also want another check in the web server to prevent hackers from attempting to upload very large files to cause a DoS.
– John Wu
Nov 14 '18 at 6:38