File upload field name

Hello,

I am trying to upload a couple of files in a multipart/form-data request. The files are being populated to Request.Files but ServiceStack.Host.HttpFile does not have a Name property, so I have no way to identify the field that each upload represents.

So from the multipart request below, the names lightLogo & darkLogo isn’t obtainable from the Files collection:

------WebKitFormBoundary40pdOvLHBARIRfkr
Content-Disposition: form-data; name="lightLogo"; filename="v5.png"
Content-Type: image/png

------WebKitFormBoundary40pdOvLHBARIRfkr
Content-Disposition: form-data; name="darkLogo"; filename="v5d.png"
Content-Type: image/png

What would be the best way to identify multiple uploads?

Thanks,
Scott

Only the the FileName property is available, which is what we use in HTTP Apache Benchmarks. This is all that’s available in the underlying ASP.NET HttpPostedFile Type which is also what’s used by the HttpListener Request.

If you need the name in addition to the FileName, one way to send it is via the QueryString, e.g:

?Names=lightlogo,darklogo

I am not using ASP.NET, I’m using Mono.

Posting the filenames separately like that would require assurances from the client that it was going to always post the multipart segments in that particular order. But looking through the source code, the data is available from the multipart in both platforms, it’s just not exposed to Mono.

I am looking at ListenerRequest.Mono.cs and can see that the HttpMultipart.Element has e.Name … where e.Name would be the multipart field name and this is passed into HttpFileCollection files, and it’s this collection that is used by ListenerRequest.cs to populate the IHttpFile[] property on the request. So wouldn’t the field name then be available there?

Wouldn’t exposing HttpFileCollection on ListenerRequest.Mono provide the desired filenames?

If I was on ASP.NET I could check Request.OriginalRequest.Files.Keys but on Mono I can’t.

Thanks,
Scott

Ok yeah it’s hiding outside the type in the Keys collection, I’ve just surfaced it up for both self-hosts and ASP.NET in this commit.

This change is available from v4.0.53 that’s now available on MyGet.

Thanks Demis, that’s awesome, totally what I needed. Cheers :smile: