R
R
Roman Rakzin2016-10-30 22:07:17
ASP.NET
Roman Rakzin, 2016-10-30 22:07:17

How to remove the limit on uploading large files to an ASP.NET MVC server?

I only upload small files to the server.
Where can I remove this restriction?
I set it in web.config, but even if I put big numbers, files, say 100-200 meters, are not downloaded. Did like here stackoverflow.com/questions/16287706

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483647" />
      </requestFiltering>
    </security>
    ...
</system.web>

Although, the reason may be in the client ... I do not send the browser, but the program with the WebClient. Maybe here somehow it is necessary to register for a larger volume?
dynamic dyn = JObject.Parse(Params.Data);
    dynamic dat = new JObject();

    using (var client = new HttpClient())
    using (var formData = new MultipartFormDataContent())
    using (var fileStream = File.OpenRead(dyn.FullPath.ToString()))
    {
       HttpContent fileStreamContent = new StreamContent(fileStream);
       var filename = Path.GetFileName(dyn.FullPath.ToString());
       formData.Add(fileStreamContent, "upload", filename);// загрузка
       var response = client.PostAsync("http://localhost:2613/siteapi/postfile?code="+ dyn.Code.ToString(), formData).Result; //Отправка
   }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2016-11-03
@kttotto

It's not about the limit, it's about ".Result;" on .PostAsync(). It blocks the sending, in theory you should have time to load 10-20 kB)). Change it to async/await throughout the file download chain, it should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question