public void AddUpdateAsync(string content, string imagePath)
{
string query = "/updates";
string fileName = Path.GetFileName(imagePath);
HttpMultipartMimeForm form = new HttpMultipartMimeForm();
form.Add("update[body]", content);
using (MemoryStream ms = new MemoryStream())
{
Image img = Image.FromFile(imagePath);
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageBytes = ms.ToArray();
HttpContent pic = HttpContent.Create(imageBytes, "application/octet-stream");
form.Add("update[picture]", fileName, pic);
lock (httpAsyncClientLock)
{
//jako state przekazujemy cały obiekt,aby można było pobrać później z niego ResponseMessage
blipHttpClientAsync.BeginSend(
new HttpRequestMessage("POST", new Uri(query, UriKind.Relative), form.CreateHttpContent()),
new AsyncCallback(AfterAddStatusAsync), blipHttpClientAsync);
}
}
}