3

I have an issue uploading large files in the MVC.NET Core application. No matter what I do I get back a 404 no data response

Here is my task method that uploads file

        [RequestSizeLimit(40000000)]
    public static async Task<string> UploadAttachment(string bis232JsonString, string url, string formType, string token, long maxResponseContentBufferSize)
    {
        var result = "Error";
        try
        {
            // To Do : Use ConfigurationManager.AppSettings["endpoint"];
            string endpoint = $"{url}/{formType}Attachment/post";

            using (var client = new HttpClient())
            {

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //client.MaxResponseContentBufferSize = maxResponseContentBufferSize;

                using (var request = new HttpRequestMessage(HttpMethod.Post, endpoint))
                {
                    request.Content = new StringContent(bis232JsonString, Encoding.UTF8, "application/json");
                    using (var response = await client.SendAsync(request))
                    {
                        if (response.IsSuccessStatusCode && (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.NoContent))
                            result = "Success";
                        else
                            result = "Error";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            //to do : Log application error properly
            result = "Error";
        }

        return result;
    }

I tried the following

  1. Tried to use MaxResponseContentBufferSize property of HTTP Client
  2. Tried to use [RequestSizeLimit(40000000)] decorator
  3. Tried to use [DisableRequestSizeLimit] decorator
  4. Tried to update the upload limit globally as shown below

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseKestrel(options =>
        {
            options.Limits.MaxRequestBodySize = 52428800; });
    

However, no matter what I try to do, nothing seems to work

Please let me know if there is anything that could be done to make it work

James
  • 1,081
  • 4
  • 15
  • 34
  • 1
    Did you see settings in IIS? https://learn.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/ – T.S. Dec 07 '18 at 03:51
  • Which of two layers fails? You seem to call some ".../Attachment/post" method from your outer MVC `UploadAttachment` method. Some debugging should clarify how far your request goes... – Alexei Levenkov Dec 07 '18 at 03:55
  • Alexey I get a response who properties say 404 error (Not Found). Are there any specific properties in the response I should check? – James Dec 07 '18 at 04:02
  • T.S. It fails in the localhost. Should I still look into IIS settings? – James Dec 07 '18 at 04:08
  • Misha, localhost or server/site - is not related. IIS has bunch of settings that regulate requests size, query string size , etc. See link above – T.S. Dec 07 '18 at 05:16
  • Лёха, should I modify applicationhost.config? I am sort of running out of options here .... – James Dec 07 '18 at 05:36
  • Share us the code for controller action `Attachment/post`. I am wonderhing whether you miss `/` between `{formType}` and `Attachment`. Try to send the request from postman. – Edward Dec 10 '18 at 05:43
  • We did try to use the Postman, but the upload never finishes - and no attachment created in the Backend/SharePoint. – James Dec 10 '18 at 18:55
  • We ARE able to upload smaller size files – James Dec 10 '18 at 18:56
  • [duplicate] https://stackoverflow.com/questions/38698350/increase-upload-file-size-in-asp-net-core – osynavets Dec 24 '19 at 23:02

0 Answers0