JAVA SDK Upload File to FileShare with SASToken return InvalidHeaderValue

NeilWang 20 Reputation points
2024-06-03T09:35:08.3633333+00:00

In my Spring Boot project, I have included the azure-storage-blob dependency. I have created a file share in Azure Storage and obtained the SAS token. When using the SDK, the downloadToFile() and exists() methods work without issues, but when trying to use the upload() method to upload a file to the file share, I consistently receive the following error:

Status code 400, "<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not in the correct format.

RequestId:9d7f6931-701a-006b-4895-b5f8d3000000

Time:2024-06-03T09:04:42.4658381Z</Message><HeaderName>Content-Length</HeaderName><HeaderValue>24</HeaderValue></Error>

However, when using the SAS token with the AZCopy tool to upload the file, it succeeds. Why is this happening, and how can I successfully upload to the file share using the SAS token and BlobClient?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,538 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anand Prakash Yadav 7,400 Reputation points Microsoft Vendor
    2024-06-04T08:45:30.6333333+00:00

    Hello NeilWang, I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept" the answer. Accepted answers show up at the top, resulting in improved discoverability for others.

    Issue: You can use the Java SDK to interact with Azure File Share programmatically, such as uploading and downloading files. To access the file share, you need to provide a SAS token. However, customer is encountering an error when trying to upload a file to the file share using the upload() method of the BlobClient class. The error message looks like this:

    Status code 400, "InvalidHeaderValueThe value for one of the HTTP headers is not in the correct format.

    RequestId:9d7f6931-701a-006b-4895-b5f8d3000000

    Time:2024-06-03T09:04:42.4658381ZContent-Length24

    Cause: Customer was using incorrect SDK.

    Solution: Customer used the correct SDK for File Share i.e., azure-storage-file-share which fixed the issue.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. NeilWang 20 Reputation points
    2024-06-04T01:32:43.8033333+00:00

    I have solved the issue. I was using the wrong SDK. For File Share, I should use azure-storage-file-share.

    0 comments No comments