httppostedfilebase - Bringing null when I have many files with the big name

Asked

Viewed 159 times

1

Good morning Next friends

I have a web system mvc with c# and need to upload several files simultaneously. Until then, all right, but when the files have a big problem name I will exemplify.

I have 5000 XMLS to be imported with the name "Nfe35160870940994008196550100004554491586403310.xml"

when I select 10 up to 20 files all go to the controler, now above that goes null.

Now when I change the file name to "A" getting A(1), A(2)... consegio send to the controller more until 2000 at once.

I don’t know what else to do, just increase the maxRequestLength to the maximum

follows abiaxo the code I use CSHTML

 @using (Html.BeginForm("ImportarXML", "LeituraNfe", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="col-md-12">
        <div class="col-md-4">
            <label>Selecione arquivos para importação</label><br />
            <input type="file" multiple="multiple" name="postedFilesBases" />
        </div>
        <div class="col-md-2">
            <label></label><br />
            <input type="submit" value="Importar" class="btn btn-primary btn-sm" />
        </div>
    </div>
}

Controller

public ActionResult ImportarXML(List<HttpPostedFileBase> postedFilesBases)
{
    try
    {
        var h = new List<XmlDocument>();
        foreach (var item in postedFilesBases)
        {
            var document = new XmlDocument();
            document.Load(item.InputStream);
            h.Add(document);
        }
		postedFilesBases.Clear();
		foreach (var item in h)
		{
			//Faça algo
		}
	}
	cath(Exception ex)
	{
		//erro
	}
}

  • Using Fiddler or other similar tool, you have checked whether your post is going integer or corrupting / truncating?

  • Leando, I have not tested with them not only can see that in the controller comes null

  • use Ienumerable<Httppostedfilebase>

  • Searching I found this https://weblogs.asp.net/hosamkamel/resolving-maximum-request-length-exceeded-exception it seems that there is a maximum size in the request, I hope it helps.

  • Ola solved the problem just switching to upload the full Directory instead of individual files

1 answer

0


Ola solved the problem just switching to upload the full Directory instead of individual files see below how the code snippet was note the commented line that was before and now like this

@using (Html.BeginForm("ImportarXML", "LeituraNfe", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="col-md-12">
        <div class="col-md-4">
            <label>Selecione arquivos para importação</label><br />
            <input type="file" name="postedFilesBases" directory mozdirectory webkitdirectory/>
            @*<input type="file" multiple="multiple" name="postedFilesBases" />*@
        </div>
        <div class="col-md-2">
            <label></label><br />
            <input type="submit" value="Importar" class="btn btn-primary btn-sm" />
        </div>
    </div>
}

Browser other questions tagged

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