Q:

web api post image with custom data

I am trying to post some custom data with image to web api. Please take a look at the method below.
public void Post(FlyerDetails FlyerDetails)
    {
        var httpRequest = HttpContext.Current.Request;
        if (httpRequest.Files.Count > 0)
        {
            foreach (string file in httpRequest.Files)
            {
                var filePath = HttpContext.Current.Server.MapPath("~/Flyers/" + httpRequest.Files[file].FileName);
                Bitmap bmp = new Bitmap(httpRequest.Files[file].InputStream);
                Graphics g = Graphics.FromImage(bmp);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.DrawString(FlyerDetails.Message, new Font(FlyerDetails.FontColor, FlyerDetails.FontSize), Brushes.DarkRed, new PointF(0, 0));
                g.Flush();
                bmp.Save(filePath);
            }
        }
    }

Now the problem is when i keep this method with parameter and post the data from fiddler it shows me 415 Unsupported Media Type error . If i remove the parameter then it is working fine. But i really need to pass the data along with the posted image.
Can any one suggest a good way to accomplish this ?
Thanks

A:

After searching a lot i figured out the way to upload the data along with the image. Here is the revised version of the code. Hope that it will helpful to someone.
public async Task<HttpResponseMessage> Post()
    {

        var streamProvider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/Flyers/"));
        await Request.Content.ReadAsMultipartAsync(streamProvider);

        var response = Request.CreateResponse(HttpStatusCode.Created);
        var filePath = "";// file path
        if (System.IO.File.Exists(filePath))
        {
            string extension = Path.GetExtension(filePath);
            Bitmap bmp = new Bitmap(filePath);
            Graphics g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            Color brushColor = System.Drawing.ColorTranslator.FromHtml(streamProvider.FormData["FontColorCode"]);
            g.DrawString(streamProvider.FormData["FontFamily"], new Font(brushColor.Name, Convert.ToInt32(streamProvider.FormData["FontSize"])), new SolidBrush(brushColor), new PointF(0, 0));
            g.Flush();
            bmp.Save(HttpContext.Current.Server.MapPath("~/" + Guid.NewGuid() + extension));
            response.Headers.Location = new Uri(new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority) + "/Flyers/" + Guid.NewGuid() + extension);
        }
        return response;
    }

NOTE : One should post the data as mutipart-formdata.

