0

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

2
  • 1
    The problem is with your x-ms-date header. Please check REST API documentation for correct format. HTH. Commented Feb 5, 2015 at 14:30
  • Well the documentation suggests the following PUT yourstorageaccount.blob.core.windows.net/… HTTP/1.1 Content-Type: application/octet-stream x-ms-version: 2011-08-18 x-ms-date: 2011-01-17 x-ms-blob-type: BlockBlob Host: yourstorageaccount.blob.core.windows.net Content-Length: 4045744 Expect: 100-continue If I change the date format to 2015-02-05 it does not change anything Commented Feb 5, 2015 at 19:14

1 Answer 1

0

According to this documentation here:

All authenticated requests must include the Coordinated Universal Time (UTC) timestamp for the request. You can specify the timestamp either in the x-ms-date header, or in the standard HTTP/HTTPS Date header. If both headers are specified on the request, the value of x-ms-date is used as the request's time of creation. The storage services ensure that a request is no older than 15 minutes by the time it reaches the service. This guards against certain security attacks, including replay attacks. When this check fails, the server returns response code 403 (Forbidden).

Your 2015-02-05 if far from valid UTC date format.

And according to this documentation here, and the sample PUT request, the Date header is represented as x-ms-date: Wed, 23 Oct 2013 22:41:55 GMT

There is no single in the Azure Blob REST API documentation where Date is referred to as yyyy-mm-dd format.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you I will change the format - however this example shows the format - msdn.microsoft.com/en-us/library/azure/jj129593.aspx - Perform the File Upload
You refer to Azure Media Services Documentation. And all references for the Media Services API are correctly formatted. Also, the part of the article that mentioned upload file to Blob explicitly refers with a link to the BLOB API documentation. And at the end, the expected format of headers are clearly described in the appropriate part of the Azure REST Management API documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.