title: WebAPI: Upload picture & get byte array
body: <p>I want the user to be able to upload a file via my application. I don't have DB access, all my data calls get completed via a web-service that another person is writing. I needed to secure the web service, so I've consumed it &amp; exposed it via WebAPI, &amp; added OAuth security.</p>
  
  <p>Now to my problem.</p>
  
  <p>I've written the following.</p>
  
  <pre><code>        public Task&lt;FileResult&gt; Post()
          {
               if (Request.Content.IsMimeMultipartContent())
               {     
                    var task = Request.Content.ReadAsByteArrayAsync().ContinueWith(
                           o =&gt;
                          {
                              var result = this.Client.UploadPicture(this.UserId, o.Result);
  
                              if (result.ResultCode == 0)
                              {
                                  return new FileResult()
                                  {
                                      Message = "Success",
                                      FileId = result.ServerId
                                  };
                              }
  
                         throw new HttpResponseException(...);
                    });
  
                return task;
               }
          ...
         }
  </code></pre>
  
  <p>I'm pretty much a noob when it comes to WebAPI &amp; multithreading (I'm not sure why this needs to be handled async? I'm sure there is a reason, but for now I'd just like a working example and get to the why later..). </p>
  
  <p>My code is loosely based on some R&amp;D &amp; samples I've found on the net, but i haven't come across a scenario like I'm needing to complete... Yet it doesn't seem like I'm doing something out of the ordinary...</p>
  
  <p><strong>Upload a file to the server, and pass the image byte[] object to either sql or another service?</strong></p>
  
  <p>In this line</p>
  
  <pre><code>    var result = this.Client.UploadPicture(this.UserId, o.Result);
  </code></pre>
  
  <p>I'm uploading a byte[] array of something....</p>
  
  <p>Then later (the retrieval method works, I've managed to retrieve &amp; view a test image)</p>
  
  <p>When retrieving the byte array of the "image" i uploaded i get an array of idk what.. EG, i get a valid result of something, but it ain't no picture. Which leads me to believe that the uploaded data is bogus :|</p>
  
  <p>O_o
  How to get the image byte[]?</p>