How to get a binary file from HTTP request body?

How to get a binary file from HTTP request body?

Hi guys,

I'm building a RESTful API and I need to receive a binary file from the HTTP body request. How can I get the binary data???

I'm trying to use methods from the HTTPRequestHandler but I didn't found any method to do this.

Please, help me :)
Carlos -

You can use the "GetRequestFiles" Action in HTTPRequestHandler. :)

Hi Justin,

I've tried and it didn't work.

To test this, I'm using a Chrome tool called Dev HTTP Client. In the headers, I put Content-Type: multipart/form-data (I've read that this structure is only filled this way) and I pass a file through the body but GetRequestFiles is always empty. By the way, I do a HTTP Post. Is that ok?
Carlos -

That's strange. It *should* be fine with POST.

I would try using GetRequestContent to verify that what you expect to see is being passed at all.

Hi Justin,

This is the request content (I hide some information with ????):

POST /?????????/CreateOrUpdateEducatorNotes.aspx?EducatorNoteId=55&UserId=2&Description=Test&TagDailyMoodId=5&ClassroomIdsToAssociate=5,4 HTTP/1.1
Connection: keep-alive
Content-Length: 879394
Content-Type: multipart/form-data
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,pt;q=0.6,pt-PT;q=0.4,es;q=0.2
Cookie: osVisitor=f163c2b7-0190-4a64-a859-ebb2ee56318e; ASP.NET_SessionId=eaa5yqzzyarxz045vpcm3lbx; ServiceCenter=08-07-2013 22:40:0711969731124; pageLoadedFromBrowserCache=true
Host: ??????
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm

????JFIF``??Adobed??]ExifMM*2b;vGFGI???? ?i}?2009:03:12 13:46:42Corbis?????54??54??2008:03:14 13:59:262008:03:14 13:59:26)19HH????JFIF??C
???w!1AQaq"2?B???? #3R?br?
$4?%?&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz?????????????????????????????????????????????????????????????????????????? ?K????|`?*[m?Gx?*??)=?r|??<?)?.f?Y~b=q?xv?U???s/#???j??kH?1?????? ??n?^?1q\s?`?]?B????<???????E"?"??7D:?K?V.?I?dS??j??w?2l???=H???u? ??q??~ ,??p???Wm.J??? x???nh??F???;??????ocW????R?&??????vz????,bf??'???~5n?k[L?Dm?=??,??7?7TWrk&N7)??S%???I#??S0??U??c

It seems like the binary file is there!

Yes, it's there, but it doesn't look right to me.

The content-type is "multipart/form-data", but the body is not formatted to indicate the different parts or the encoding types, the body itself *is* the binary data. There's no boundaries, for example.

See the RFC for details:

Many thanks Justin!

Thanks to you, I've tried another client (Fiddler) and now I see the differences. The request is different and the image is already "catched".

I hope this is a bug on the first client I was using! :)
Carlos -

Glad to help! It definitely sounds like a bug with that tool.