JAVA SDK Upload File to FileShare with SASToken return InvalidHeaderValue

NeilWang 20 Reputation points

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.



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

    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.



    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

    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