Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

File input no longer posting #5076

Closed
kichalla opened this issue Jul 25, 2016 · 11 comments
Closed

File input no longer posting #5076

kichalla opened this issue Jul 25, 2016 · 11 comments
Assignees

Comments

@kichalla
Copy link
Member

From @MihaiBratulescu on July 4, 2016 7:10

I have a few of these file inputs:

<input id="ZoneOfAnalysisFiles[@Model.Key].Key" name="ZoneOfAnalysisFiles[@Model.Key].Key" value="@Model.Value.Identification" hidden />

<input id="ZoneOfAnalysisFiles[@Model.Key].Value" name="ZoneOfAnalysisFiles[@Model.Key].Value" 
                                   type="file" multiple style="display:inline-block">

The keys get posted but not the files. In Request.Form.Keys the Value keys are missing for the file inputs but if I change to text it's working all the sudden.

This has been happening since I upgraded to RTM and worked fine in RC2.

My project.json :

{
  "userSecretsId": "aspnet-WNCT.Web-f9ad84ae-9b95-4000-ab80-3ecdf4814421",

  "dependencies": {
    "Microsoft.AspNetCore.Session": "1.0.0",
    "Microsoft.AspNetCore.Hosting": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Serilog": "2.0.0-rc-602",
    "Serilog.Sinks.RollingFile": "2.0.0-rc-703",
    "Serilog.Extensions.Logging": "1.0.0-rc2-10110",
    "HtmlAgilityPack": "1.4.9",
    "LDAP": "1.0.0",
    "WNCT.BL": "1.0.0-*",
    "WNCT.Domain": "1.0.0-*",
    "WNCT.EF": "1.0.0-*"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net451": {}
  },

  "buildOptions": {
    "platform": "x86",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  //"runtimes": { "win": [ "win7-x86" ] },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Is there a solution out there?

Copied from original issue: dotnet/aspnetcore#1631

@kichalla kichalla self-assigned this Jul 25, 2016
@kichalla
Copy link
Member Author

From @Tratcher on July 5, 2016 16:32

Is it in Request.Form.Files?

@kichalla
Copy link
Member Author

From @MihaiBratulescu on July 5, 2016 16:55

@Tratcher Yes, I now see it's posting but not binding to the dictionary (IDictionary<string, IEnumerable>) from my model.

@kichalla
Copy link
Member Author

From @Tratcher on July 5, 2016 16:58

@rynowak @kichalla ?

@kichalla
Copy link
Member Author

From @MihaiBratulescu on July 5, 2016 17:3

Sorry I swear I wrote something else, my model is:

public class ScopeModel
{
public IDictionary<string, IEnumerable<IFormFile>> ZoneOfAnalysisFiles {get;set;}
....
}

@kichalla
Copy link
Member Author

From @prilutskiy on July 5, 2016 23:14

@MihaiBratulescu, Do you have enctype attribute of the form set to multipart/form-data?

@kichalla
Copy link
Member Author

From @MihaiBratulescu on July 6, 2016 13:17

@prilutskiy Yes, like I said it worked in RC2. I have the same problem on a different machine at home.

@kichalla
Copy link
Member Author

I am looking at it now.

@kichalla
Copy link
Member Author

Could you share how your raw request looks like?(ex: browser developer tools) I am not interested in the files being uploaded but the individual parts' headers(because for model binding purpose how the key names are important). So following is the model you are binding to?

public class ScopeModel
{
public IDictionary<string, IEnumerable<IFormFile>> ZoneOfAnalysisFiles {get;set;}
....
}

@kichalla
Copy link
Member Author

From @MihaiBratulescu on July 6, 2016 21:27

@kichalla not sure what you ask for but here is a more simple example that also does not work:

Model:

    public class UploadModel
    {
        public IDictionary<string, IEnumerable<IFormFile>> Files { get; set; }
    }

View:

<form method="post"  enctype="multipart/form-data" action="/Home/Upload">

   @for (int i = 0; i < 3; i++)
   {
       <input type="text" hidden id="Files[@i].Key" name="Files[@i].Key" value="@(i)File" />
        <input type="file" multiple id="Files[@i].Value" name="Files[@i].Value" />
   }
    <button type="submit">Submit</button>
</form>

Controller:

[HttpGet]
        public IActionResult Upload()
        {
            return View();
        }

        [HttpPost]
        public IActionResult Upload(UploadModel form)
        {
            return View();
        }

As for the headers:

Request URL:http://localhost:54821/Home/Upload
Request Headers
Provisional headers are shown
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryB2Y9SIARh3WgqkPB
Origin:http://localhost:54821
Referer:http://localhost:54821/Home/Upload
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Request Payload
------WebKitFormBoundaryB2Y9SIARh3WgqkPB
Content-Disposition: form-data; name="Files[0].Key"

0File
------WebKitFormBoundaryB2Y9SIARh3WgqkPB
Content-Disposition: form-data; name="Files[0].Value"; filename="somefile.torrent"
Content-Type: application/x-bittorrent

------WebKitFormBoundaryB2Y9SIARh3WgqkPB
Content-Disposition: form-data; name="Files[1].Key"

1File
------WebKitFormBoundaryB2Y9SIARh3WgqkPB
Content-Disposition: form-data; name="Files[1].Value"; filename=""
Content-Type: application/octet-stream

------WebKitFormBoundaryB2Y9SIARh3WgqkPB
Content-Disposition: form-data; name="Files[2].Key"

2File
------WebKitFormBoundaryB2Y9SIARh3WgqkPB
Content-Disposition: form-data; name="Files[2].Value"; filename=""
Content-Type: application/octet-stream

------WebKitFormBoundaryB2Y9SIARh3WgqkPB--

@kichalla
Copy link
Member Author

Thanks! for the simple repro. cc @dougbu

@kichalla kichalla modified the milestone: 1.0.1 Jul 25, 2016
@Eilon Eilon added this to the 1.1.0 milestone Jul 25, 2016
@Eilon Eilon added the bug label Jul 25, 2016
@kichalla
Copy link
Member Author

kichalla commented Aug 4, 2016

ac98417

@kichalla kichalla closed this as completed Aug 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants