title: Post C# MultipartFormContent application/octet-stream Winform HttpClient
body: <p>I am trying to post one or more files from my local machine to an API with <code>HttpClient</code>, <code>MultipartFormContent</code> and ContentType: <code>"application/octet-stream"</code> but when i do postSync and call an API from a local Winform application,  the result of the task (<code>var response = task.Result;</code>) says that it is "Unsopported Type File" StatusCode: 415. I tried with <code>ByteArrayContent</code> but was still unsuccessful.</p>
  
  <p>This is my code:</p>
  
  <pre><code>    bool Upload(string url, string path, string localFilename, string fileName, string projectId, string folderId)
      {
          Boolean isFileUploaded = false;
          string xapiKey = "-----";
          try
          {
              HttpClient httpClient = new HttpClient();
              httpClient.BaseAddress = new Uri(url);
              httpClient.DefaultRequestHeaders.Add("x-api-key", xapiKey);
  
              var fileInfo = new FileInfo(localFilename);
              FileUpload uploadResult = null;
              bool _fileUploaded = false;
  
              //Extract content file
              FileStream fileStream = File.OpenRead(path);
              var streamContent = new StreamContent(fileStream);
              streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
              streamContent.Headers.ContentDisposition.FileName = "\"" + Path.GetFileName(path) + "\"";
              streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octetstream");
              string boundary = Guid.NewGuid().ToString();
              MultipartFormDataContent content = new MultipartFormDataContent(boundary);
              content.Headers.Remove("Content-Type");
              content.Headers.TryAddWithoutValidation("Content-Type", "mulitpart/form-data; boundary=" + boundary);
              content.Add(streamContent);
  
              //content.Add(new StreamContent(fileStream), "\"file\"", string.Format("\"{0}\"", fileName + fileInfo.Extension));                
  
              Task taskUpload = httpClient.PostAsync(url, content).ContinueWith(task =&gt;
              {
                  if (task.Status == TaskStatus.RanToCompletion)
                  {
                      var response = task.Result;
                      if (response.IsSuccessStatusCode)
                      {
                          uploadResult = response.Content.ReadAsAsync&lt;FileUpload&gt;().Result;
                          if (uploadResult != null)
                              _fileUploaded = true;
                      }
                  }
  
                  fileStream.Dispose();
              });
              taskUpload.Wait();
              if (_fileUploaded)
                  isFileUploaded = true;
              httpClient.Dispose();
          }
          catch (Exception ex)
          {
              isFileUploaded = false;
              throw new Exception(ex.Message);
          }
          return isFileUploaded;
      }
  </code></pre>