1

I'm having the problem with sending a file as a byte array json string to the server. When the file is relatively small: up to 2MB or so, then it works fine, but if the file is like 4MB then the request throws error (it doesnt even reach the controller in the backend).

Error:

XMLHttpRequest cannot load http://localhost:61416/api/organisationdocuments/.
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:51080' is therefore not allowed access. 
The response had HTTP status code 404.

In the startup.cs I have

 // Add CORS support.
        services.AddCors(options =>
        {
            options.AddPolicy("AAPolicy", policyBuilder =>
                policyBuilder
                    .AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials()
                );
        });

In the front-end I use angularjs. The method looks like this:

this.addFile = function (file) {
            return $http.post(fileApi, file);
        };

I debuged it on the front and it looks alright, except the string with the byte array is so big it hangs my browser sometimes. So As I mentioned, it works for smaller files, only occurs for the bigger ones. It obviously has to do something with the weight of the file.

I tried to debug back-end, but it doesnt even reach the controller, so there is no way. Any ideas? Thanks a lot!

Edit:

My web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <httpRuntime maxRequestLength="10000000" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="10000000" />
      </requestFiltering>
    </security>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" />
  </system.webServer>
</configuration>
  • Does the error occur with other web-servers such as Kestrel or WebListener? – mausworks Jan 15 '16 at 08:32
  • 1
    Have you tried to look into solving the CORS issue instead? http://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-5 – Guo Hong Lim Jan 15 '16 at 08:45
  • @diemaus I'm doing it on Kestrel right now, I haven't try it on other servers. Guo Hong Lim It is not an issue, I set it up right in Startup.cs class. Besides, it works with smaller files just right – Richard Rahl Jan 15 '16 at 12:32
  • @RichardRahl any update on this, I'm interested in knowing if this has been solved. – mausworks Jan 19 '16 at 14:03
  • 1
    As it's a .NET Core issue, which is in early developement I managed to go across CORS problem, but as I thought it was a red herring. I have put this on hold, because this may be an MVC bug, I will see in a couple of weeks if anything changed. – Richard Rahl Jan 20 '16 at 14:54

2 Answers2

0

add this to your Web.Config, it will allow you to upload the content up to 10MB. (10000000 = 10 MB)

<system.web>
  <httpRuntime maxRequestLength="10000000" />
</system.web>

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

Hope this help

vantian
  • 848
  • 3
  • 10
  • 25
0

you must using chunk approach to do that or use stream array

check this link

Esi
  • 389
  • 5
  • 14