Limit for sending files

Asked

Viewed 3,825 times

3

I have a project in Asp Net MVC . NET Framework 4 as follows:

View:

<div class="file-content">
    <label class="custom-file-upload">
          <input type="file" id="importar-arquivos" multiple accept=".pdf" name="arquivo" required />
          <span class="ui-icon ui-icon-circle-arrow-n file-icon"></span> Escolher Arquivos
    </label>
    <br />
    <span id="file-selected">​​</span>
</div>

<div class="options-content">
    <img src="../Images/save-send.png" id="file-enviar" class="icon-action" title="Enviar" />
    <img src="../Images/btnerror.png" id="file-cancelar" class="icon-action" title="Cancelar" />
</div>

<script>
    (function () {
        $("#file-enviar").on("click", function () {
            try {
               var fileImput = $("#importar-arquivos");
                var arquivos = fileImput.get(0).files;

                if (arquivos.length > 0) {

                    prepararPDF(arquivos);

                } else {
                    alert("Selecione os arquivos para enviar!");
                }
            } catch (ex) {
                console.error("Erro ao enviar arquivo!", ex);
            }
        });

        function prepararPDF(arquivos) {
            var paramsData = new FormData();
            for (var i = 0; i < arquivos.length; i++) {
                paramsData.append("files", arquivos[i]);
            }

            enviarPDF(paramsData);
        }

        function enviarPDF(paramsData) {
            $.ajax({
                beforeSend: function () {
                    IniciaLoad();
                },
                complete: function () {
                    FinalizaLoad();
                },
                contentType: false,
                processData: false,
                dataType: "json",
                type: "POST",
                url: "minhaURL",
                data: paramsData,
                success: function (data) {
                    console.debug("data", data);
                },
                fail: function () {
                    alert("Falhou!");
                },
                error: function () {
                    alert("Erro de Conexão");
                }
            });
        }

    })();
</script>

Controller:

[HttpPost]
public ActionResult MinhaAction(HttpPostedFileBase[] files)
{
   return Json(files.Length, JsonRequestBehavior.AllowGet);
}

When performing tests with few small files nay got no problem, but while trying to send multiple larger files then got the following error:

HTTP Error 404.13 - Not Found
The request filtering module is configured to deny a request that exceeds the requested content size.


  1. The problem is the amount of files, the size of each theirs or the sum of the size of all files?
  2. What is the default limit for amount of archives and size theirs?
  3. How can I set a higher limit?

3 answers

6


There are two settings to be modified.

maxRequestLength indicates the maximum size of an upload supported by ASP.NET maxAllowedContentLength specifies the maximum content size of a request supported by IIS.

Expand the acceptable file size by adjusting the following file entry web config.:

web config.

 <system.web> 
     <httpRuntime maxRequestLength="104857600"/> 
 </system.web>
 <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="104857600"/>
      </requestFiltering>
    </security>
  </system.webServer>

Where maxAllowedContentLength is measured in bytes, whose default value is 30000000, (approximately 28.6MB).

The maximum number of sequential files to be sent is 4.294.967.295 (NTFS) or by the sum of their sizes plus the Multipart header, whichever is less.

In case the problem persists, it may be in fact that the settings made in the file web.config may be replaced by definitions both in applicationhost.config how much in machine.config.

If you have access to these, check if the property overrideModeDefault of the corresponding sections are defined as Allow, as in the following example:

machine config.

<requestFiltering overrideModeDefault="Allow">
    <requestLimits maxAllowedContentLength="104857600"/>        
</requestFiltering>

There is, as far as I know, no way to override these settings if you do not have access to the corresponding configuration file.

Source.

  • Thank you so much for sharing your wisdom @Onosendai , but I want to get even more! What would be the default file size limit? What file limit (quantity) can I submit in a single request?

  • @Jedaiasrodrigues Answers added to the answer. =)

  • from what I understood the 4,294,967,295 files would be the limit for an NTFS directory, this limit also applies for a POST as I am doing? I believe the amount of files is more related to the maxAllowedContentLength as you well quoted... I’m sure?

  • 1

    @Jedaiasrodrigues correct. Limiting the amount of files is only relevant for NTFS.

1

In the httpRuntime within your web.config you can specify the maxRequestLength which will determine the maximum size of your requests.

The maximum size of requests, in kilobytes. The default size is 4096 KB (4 MB).

Source

There are other questions and answers on the subject.

/a/94181/5846

/a/114102/5846

  • 4 MB per file or the sum of all cannot go beyond this? That is, I can send 2 files of 3 MB of good?

  • I’m not sure, but I believe it’s the sum of the files

  • Thank you so much for the answer! @Elifaziobernadesdasilva says that the limit is for each file... http://answall.com/a/155906/23192

  • In fact you are right! I just tested here and I could prove that the limit is the sum of the size of all files in the same request.

  • But you also need to configure the maxAllowedContentLength as quoted by @Onosendai

0

The default size limit for each file is 4mb or 4096 KB on Asp.net

To set the size for the entire application, simply add the following to your web.config:

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

The value xxx you replace with the maximum value you want to allow in kb.

  • You said: "To set the size for the entire application [...]". But it is possible to set a larger size only for a specific context?

  • If the default limit is for each file, then in theory I can send 100 files of 3.5 MB?

  • I did some tests here and I could see that the limit is not for each file, but for the sum of the size of all files sent in the same request.

Browser other questions tagged

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