Put Range (FileRest API) - The value for one of the HTTP headers is not in the correct format

Donnie Graham 5 Reputation points
2025-05-20T13:42:43.3433333+00:00

I'm having issues calling the Put-Range method on the File Rest API.

I can create the file fine, but when attempting to call the Put-Range method I'm getting the below error:

<Error>The value for one of the HTTP headers is not in the correct format.

<HeaderName>Content-Length</HeaderName>

<HeaderValue>19124</HeaderValue>

</Error>

I've tried lots of variations, these are the headers I'm passing in with the put-range request:

x-ms-range: bytes=0-19123

x-ms-date: Tue, 20 May 2025 13:37:58 GMT'

x-ms-write: update

x-ms-version: 2025-05-05

Content-Length: 19124

User-Agent: axios/1.9.0

Am I missing something obvious here?

Cheers,

Donnie

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,425 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vinod Kumar Reddy Chilupuri 4,185 Reputation points Microsoft External Staff Moderator
    2025-05-20T15:15:58.68+00:00

    Hi Donnie Graham,

    The error message you're encountering indicates that the Content-Length header value may not be matching the expected size based on the range specified in the x-ms-range header.

    In your case, you have specified x-ms-range: bytes=0-19123, which indicates that you are trying to write 19124 bytes (from byte 0 to byte 19123 inclusive). Therefore, the Content-Length should also be set to 19124, which it appears you have done correctly.

    1. Content-Length: Make sure that the Content-Length indicates the exact number of bytes you are sending in the body of the request. If you are trying to send a specific range with x-ms-range, the Content-Length should equal the size of that range you're attempting to update.
    2. x-ms-range format: Your x-ms-range: bytes=0-19123 seems fine but ensure you're not exceeding the maximum size limit of 4 MiB if that's applicable here.
    3. Request Body: Make sure you're actually sending a body with the PUT request. If there's no content in the body, the Content-Length should be set to 0, but if you're sending data, ensure that the Content-Length matches the data you're transmitting.
    4. Date Format: The x-ms-date header must be correctly formatted. It appears you have an extra apostrophe after the timestamp—ensure that you remove that.

    Specifying the range header for File service operations

    Hope the above suggestion helps! Please let us know do you have any further queries.

    Please do consider to “Accept the answer” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. Venkatesan S 2,820 Reputation points Microsoft External Staff Moderator
    2025-05-22T12:23:02.5366667+00:00

    Hi @Donnie Graham ,

    <Error>The value for one of the HTTP headers is not in the correct format. <HeaderName>Content-Length</HeaderName> <HeaderValue>19124</HeaderValue> </Error>

    The error mentioned above occurs when an incorrect parameter value is passed in the request.

    You can follow the below steps which I followed in my environment:

    In my environment, I have uploaded a sample text file to the Azure file share with a size of 356B.

    Portal:

    User's image

    Note: You can update the file within the maximum limit of the existing file size.

    Now, I need to update the following sentence in the file stored in the Azure file share.

    Hi everyone, Good morning! have a great day

    The size of the above sentence is 43 bytes

    You can use the Put Range(FileRest API) below with the necessary headers to make a successful request.

    Request:

    PUT https://<storage account name>.file.core.windows.net/<filesharename>/<directory name>/<filename>?comp=range
    
    Headers:
    x-ms-range: bytes=0-42
    Content-Length: 43
    x-ms-write: update
    Authorization: SharedKey venkat326123:xxxxxxxxxxxxxxx
    x-ms-date: Thu, 22 May 2025 11:58:26 GMT
    x-ms-version: 2025-05-05
    Content-Type: application/octet-stream
    
    Body:(Text)
    Hi everyone, Good morning! have a great day
    

    Output:

    User's image

    Portal:

    User's image

    Reference:

    Put Range (FileREST API) - Azure Files | Microsoft Learn

    Hope this answer helps! please let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.