【问题标题】:Attempt to write to page blob fails with "Error: The value for one of the HTTP headers is not in the correct format尝试写入页 blob 失败并显示“错误:HTTP 标头之一的值格式不正确
【发布时间】:2019-01-27 05:08:06
【问题描述】:

我正在尝试使用 azure-storage-cpp 的 API 使用以下代码写入页面 blob:

// The code is representative. I have removed some of the error handling code.
void page_blobs_async()
{

 // Initialize storage account
  azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

  // Create a blob container
  azure::storage::cloud_blob_client blob_client = storage_account.create_cloud_blob_client();
  azure::storage::cloud_blob_container container = blob_client.get_container_reference(_XPLATSTR("my-sample-page-async-container"));

  // Return value is true if the container did not exist and was successfully created.
  container.create_if_not_exists();

  // Make the blob container publicly accessible
  azure::storage::blob_container_permissions permissions;
  permissions.set_public_access(azure::storage::blob_container_public_access_type::blob);
  container.upload_permissions(permissions);
  filename = "DataFile1.txt" // This contains '1'
  string blob_name = "async_blob"
  concurrency::streams::istream input_stream = concurrency::streams::file_stream<uint8_t>::open_istream(_XPLATSTR(filename)).get();
  azure::storage::cloud_block_blob blob1 = container.get_block_blob_reference(_XPLATSTR(blob_name));
  azure::storage::cloud_page_blob blob1 = container.get_page_blob_reference(_XPLATSTR(blob_name));
  blob1.create(16 * 1024 * 1024);
  std::cout<<"Blob write started"<<std::endl;
  blob1.upload_from_stream(input_stream);

}

我收到以下错误:

错误:HTTP 标头之一的值格式不正确。 HTTP 标头之一的值格式不正确。 请求ID:e4fe5ee9-e01e-0045-6076-386b87000000 时间:2018-08-20T11:08:57.8352526Z

标头转储:

headers Date:Mon, 20 Aug 2018 11:08:57 GMT
headers ETag:"0x8D6068BAC4DC466"
headers Last-Modified:Mon, 20 Aug 2018 10:57:08 GMT
headers Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
headers Transfer-Encoding:chunked
headers x-ms-blob-public-access:blob
headers x-ms-lease-state:available
headers x-ms-lease-status:unlocked
headers x-ms-request-id:e4fe5ebd-e01e-0045-3a76-386b87000000
headers x-ms-version:2017-04-17
headers Date:Mon, 20 Aug 2018 11:08:57 GMT
headers ETag:"0x8D6068D535B837D"
headers Last-Modified:Mon, 20 Aug 2018 11:08:57 GMT
headers Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
headers Transfer-Encoding:chunked
headers x-ms-request-id:e4fe5ec5-e01e-0045-4076-386b87000000
headers x-ms-version:2017-04-17
headers Date:Mon, 20 Aug 2018 11:08:57 GMT
headers ETag:"0x8D6068D535DE4B5"
headers Last-Modified:Mon, 20 Aug 2018 11:08:57 GMT
headers Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
headers Transfer-Encoding:chunked
headers x-ms-request-id:e4fe5ee4-e01e-0045-5b76-386b87000000
headers x-ms-request-server-encrypted:true
headers x-ms-version:2017-04-17
Blob write started
headers Content-Length:331
headers Content-Type:application/xml
headers Date:Mon, 20 Aug 2018 11:08:57 GMT
headers Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
headers x-ms-request-id:e4fe5ee9-e01e-0045-6076-386b87000000
headers x-ms-version:2017-04-17
headers Content-Length:331
headers Content-Type:application/xml
headers Date:Mon, 20 Aug 2018 11:08:57 GMT
headers Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
headers x-ms-request-id:e4fe5ee9-e01e-0045-6076-386b87000000
headers x-ms-version:2017-04-17

我正在使用 cpprestsdk-2.9.1 和 Ubuntu 16.04。

【问题讨论】:

    标签: rest azure azure-storage


    【解决方案1】:

    如果您使用Fiddler 等工具捕获请求流量,您可能会看到错误消息指向标头x-ms-blob-content-length

    Storage page blob REST API:

    页 blob 大小必须与 512 字节边界对齐。

    这是设计并在storage docs中描述:

    页面 blob 是针对随机读写操作优化的 512 字节页面的集合。

    所以我们应该确保要上传的文件长度是 512 字节的倍数。另外upload_from_stream是初始化一个新的page blob(覆盖已有的),create好像没必要提前。

    【讨论】:

      猜你喜欢
      • 2016-10-21
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 2019-02-08
      • 2015-05-12
      • 2018-09-01
      相关资源
      最近更新 更多