Rest 尝试写入页面blob失败,返回“0”;错误:其中一个HTTP标头的值格式不正确

Rest 尝试写入页面blob失败,返回“0”;错误:其中一个HTTP标头的值格式不正确,rest,azure,azure-storage,Rest,Azure,Azure Storage,我正在尝试使用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::stor

我正在尝试使用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);

}

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

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

见:

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

其设计如下所述:

页面BLOB是512字节页面的集合,针对随机读写操作进行了优化

所以我们应该确保上传的文件长度是512字节的倍数。此外,
upload\u from\u stream
是初始化一个新的页面blob(覆盖现有的页面blob),
create
似乎没有必要预先创建

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