1

I am constructing a MIME multipart stream that is a collection of various files/data the user has chosen for upload. I then PUT this stream to a URL using asp.net MVC 3 (though the MVC bit should be irrelevant to the question - similar applies to all ASP.NET), where it comes in on the server as a HttpFileCollectionBase object (which is itself basically a collection of HttpPostedFileBase objects).

This all works fine.

However, the HttpPostedFileBase only allows access to the MIME 'media type' and 'filename' fields. I have other data which I am putting in the

Content-Description:

and

Content-Disposition:

headers in the MIME multipart - but there seems to be no way to access these at the server end. Obviously I realise that media type and filename are the most common fields used and hence I have no problems with having to jump through some hoops to get some of the more esoteric MIME fields. However, I can't see any way to access them at all. Do I need to hook in my own MIME multipart decoding engine into the ASP.NET/MVC framework? If so, where are the hooks, and are there libraries out there that do this without me having to write a MIME decoder.

Andrew Patterson
  • 1,338
  • 1
  • 12
  • 26

1 Answers1

0

You can access the raw request body data using the Request.InputStream property. And to access the request HTTP headers you could use the Request.Headers property.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • But I'd have to write a custom MIME multipart decoder? I was hoping to avoid that pain. Also, from what I can tell the ASP.NET stuff handles splitting large requests into file objects etc rather than storing the whole request (mine are many megabytes) in memory. I was hoping to use all of that without me doing anything! – Andrew Patterson Oct 24 '11 at 06:04
  • @AndrewPatterson, yes you will have to write a custom MIME parser. I am afraid that what you have hoped is not possible. The ASP.NET already wrote a multipart/form-data parser and provided it to you under the form of the `HttpFileCollectionBase` class. If it doesn't suit your needs I am afraid that you have no other choice but to roll your own. – Darin Dimitrov Oct 24 '11 at 06:08
  • This seems like such a waste - it is a pity Microsoft couldn't put a field similar to Request.Headers on each of the HttpPostedFile objects that are created from the MIME multipart decode. I guess I will look into other MIME decoding libraries to see if I can avoid implementing this myself. – Andrew Patterson Oct 24 '11 at 13:06