Home > Back-end >  PageBlobClient::UploadPages throws "InvalidHeaderValue"
PageBlobClient::UploadPages throws "InvalidHeaderValue"

Time:07-30

var blobServiceClient = new BlobServiceClient(connectionString, options);

var blobContainerClient = blobServiceClient.GetBlobContainerClient("somecontainer");

var pageBlobClient = blobContainerClient.GetPageBlobClient("someblob");

await blobContainerClient.CreateIfNotExistsAsync(cancellationToken: default);

await pageBlobClient.CreateIfNotExistsAsync(0, cancellationToken: default);

pageBlobClient.UploadPages(new MemoryStream(Encoding.ASCII.GetBytes("Test")), 0);

--------------- The above code throws the below error ----------------------------------

The value for one of the HTTP headers is not in the correct format. RequestId:0761d774-b01e-0002-6a3a-a256ea000000 Time:2022-07-28T04:25:28.8145993Z Status: 400 (The value for one of the HTTP headers is not in the correct format.) ErrorCode: InvalidHeaderValue

Additional Information: HeaderName: Range HeaderValue: bytes=0-3

Content:

InvalidHeaderValueThe value for one of the HTTP headers is not in the correct format.

RequestId:0761d774-b01e-0002-6a3a-a256ea000000 Time:2022-07-28T04:25:28.8145993ZRangebytes=0-3

Headers: Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0 x-ms-request-id: 0761d774-b01e-0002-6a3a-a256ea000000 x-ms-client-request-id: ec21d32d-74ec-4942-9321-341da37e7a63 x-ms-version: 2021-08-06 x-ms-error-code: InvalidHeaderValue Date: Thu, 28 Jul 2022 04:25:27 GMT Content-Length: 320 Content-Type: application/xml

CodePudding user response:

The reason you are getting this error is because the page size should be a multiple of 512 bytes and you are only uploading 4 bytes.

From this link (range header description):

Given that pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the end offset must be a modulus of 512 – 1. Examples of valid byte ranges are 0-511, 512-1023, etc.

  • Related