简体   繁体   中英

Create path in ADLS Gen2 fails because of missing x-ms-blob-type?

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?

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:

https://xxx.dfs.core.windows.net/aaa/myfile999.txt?resource=file&sv=2019-10-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2020-07-08T10:31:37Z&st=2020-07-08T02:31:37Z&spr=https&sig=xxxx

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM