Limit file size

Asked

Viewed 1,180 times

0

I created a file import method. I would like to know how limit the size from the uploaded file to the server.

  • Did any of the answers solve the problem? Do you think you can accept one of them? See [tour] how to do this. You’d be helping the community by identifying the best solution. You can only accept one of them, but you can vote for anything on the entire site.

2 answers

5

One of the possibilities would be to add this to the web.config:

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="10000" />
    </system.web>
</configuration>

It is also possible to configure this in IIS:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="10000" />
        </requestFiltering>
    </security>
</system.webServer>

I put in the Github for future reference.

  • In a multi-file scenario, would this limit be for each of them, or the sum of the size of all? I could send 1000 files considering that the size of each of them does not exceed the limit? There is a limit to the number of files?

  • As I recall, it’s for everything, as long as it’s done on the same requisition. If each file is a separate request, then the limit is confused with the individual. To my knowledge, there is no theoretical file limit.

2

Good for you to be able to limit the size of the file uploaded on the server, just use this function:

FileInfo fileInfo = new FileInfo(@"c:\arquivo.txt");
Console.WriteLine(fileInfo.Length);

This function aims to return the file size, After picking up the file size to be uploaded, you check: if the file size is suitable Upa, otherwise not Upa.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.