I am trying to upload videos to azure media server via rest api. I have reach the step of uploading the video however I am getting an error. I use the following code to upload the video.
var client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
client.DefaultRequestHeaders.Add("x-ms-version", "2.8");
client.DefaultRequestHeaders.Add("x-ms-date", "2015-02-5");
client.DefaultRequestHeaders.Add("DataServiceVersion", "3.0");
client.DefaultRequestHeaders.Add("MaxDataServiceVersion", "3.0");
client.DefaultRequestHeaders.Add("x-ms-blob-type", "BlockBlob");
var formcontent = new MultipartFormDataContent();
FileStream stream = File.OpenRead(@"C:\AzureMediaUploadTest\MediaUploadTest\VideoFiles\tom.mp4");
byte[] fileBytes = new byte[stream.Length];
stream.Read(fileBytes, 0, fileBytes.Length);
stream.Close();
var streamcontent = new StreamContent(new MemoryStream(fileBytes));
formcontent.Add(streamcontent);
formcontent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result = await client.PutAsync(uploadurl, formcontent);
However the result gives a 400 - A http header is not in the correct format. Iam not sure which header is refered too or am I missing something.
Any help is appreciated.
UPDATE: I have marked the question as answered however I am now having issues with the authentication header - the new issue is asked here - Uploading blob to azure - Create authentication header