将 blob 上传到 azure - http header 格式不正确
Uploading blob to azure - http header not in correct format
我正在尝试通过 rest api 将视频上传到 azure 媒体服务器。我已经到了上传视频的步骤,但是我收到了一个错误。我使用以下代码上传视频。
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);
但是结果给出了 400 - http header 的格式不正确。我不确定也引用了哪个 header 还是我遗漏了什么。
感谢任何帮助。
更新:我已将问题标记为已回答,但我现在遇到身份验证问题 header - 此处提出新问题 -
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).
如果远离有效的 UTC 日期格式,您的 2015-02-05
。
并且根据 this documentation here 和示例 PUT 请求,日期 header 表示为 x-ms-date: Wed, 23 Oct 2013 22:41:55 GMT
在 Azure Blob REST API 文档中没有单独的日期被称为 yyyy-mm-dd
格式。
我正在尝试通过 rest api 将视频上传到 azure 媒体服务器。我已经到了上传视频的步骤,但是我收到了一个错误。我使用以下代码上传视频。
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);
但是结果给出了 400 - http header 的格式不正确。我不确定也引用了哪个 header 还是我遗漏了什么。
感谢任何帮助。
更新:我已将问题标记为已回答,但我现在遇到身份验证问题 header - 此处提出新问题 -
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).
如果远离有效的 UTC 日期格式,您的 2015-02-05
。
并且根据 this documentation here 和示例 PUT 请求,日期 header 表示为 x-ms-date: Wed, 23 Oct 2013 22:41:55 GMT
在 Azure Blob REST API 文档中没有单独的日期被称为 yyyy-mm-dd
格式。