Reputation: 7685
I created an Azure Storage Account with an Azure Data Lake Storage Gen2. I want to upload a file using the REST API. While using the authorization with Shared Keys works fine, I get problems using an account SAS.
For the path creation I use the Path - Create operation.
# provide Azure Data Lake Storage Gen2 URL as environment variable
$ ADLS_URL="https://xxxxx.blob.core.windows.net/files"
# provide account SAS as environment variable
$ SAS="sv=2017-07-29&ss=bf&..."
# Create a new path in ADLS Gen2
$ curl -vX PUT -H "Content-Length: 112" "$ADLS_URL/example.txt?resource=file&$SAS"
The request returns with 400 An HTTP header that's mandatory for this request is not specified.
and the following error message.
<Error>
<Code>MissingRequiredHeader</Code>
<Message>An HTTP header that's mandatory for this request is not specified. RequestId:870e754b-... Time:2020-07-07T...</Message>
<HeaderName>x-ms-blob-type</HeaderName>
</Error>
It turned out, that the missing header is required for the Creation of a blob in the Blob storage. Since the ADLS Gen2 supports both APIs and both provide a similar operation, it delegates the request to the wrong one.
Is there a way to create a path using PUT operation with a SAS on the ADLS Gen2 API?
Upvotes: 0
Views: 4852
Reputation: 29940
Yes, you can create a path(a file in this example) using PUT operation with a SAS on the ADLS Gen2 API. But you need take 3 steps: create an empty file / append data to the empty file / flush data.
Step 1: after generating a sas token, you need to call the Path - Create to create a file in ADLS Gen2. Note: the file should be empty here, it means that in the request header, Content-Length
should be 0
.
The request url looks like this:
Here, I tested it with the tool postman, it works without issue. The empty file can be created on ADLS Gen2 in azure portal:
Step 2 and Step 3:
then you should call Path - Update for appending data.
at last, call the Path - Update again for flushing data.
If you don't know how to use Path - Update for these operation, please use fiddler to see the detailed request information, or just let me know:). Here is the screenshot of the request captured by Fiddler:
BTW, I suggest you can directly use the Put Blob api with sas token(but you need to specify x-ms-blob-type
in the request header), which is just a one step for both create the file as well as upload content.
Upvotes: 1