调用ADLS Gen 2 Rest API创建文件时出错 [英] Error while calling ADLS Gen 2 Rest API to create file

查看:75
本文介绍了调用ADLS Gen 2 Rest API创建文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用创建路径的Rest API在ADLS Gen 2中创建文件。以下是用于调用API的参数


https:/ /<Accountname>.dfs.core.windows.net/<FileFolder Name> /test1.zip?resource = file&< SAS Token>



我设置了标题 


content-length:0

x-ms-version:2018-11-09



此请求仍会不断出现错误 



错误" :{

  &NBSP; &NBSP; &NBSP; "code":"ContentLengthMustBeZero",

  &NBSP; &NBSP; &NBSP; " message":"Content-Length请求标头必须为零"


}


我被困在这两天。非常感谢任何帮助


我能够成功调用List操作

解决方案

您好那里,


要使用ADLS Gen2的REST API,您还需要授权标头。此外,URL还直接具有SAS令牌(不作为参数)。 


使用ADLS Gen2 API(使用OAuth2)创建文件的简单方法是:


1。通过向 https:// login发出POST请求来获取Access令牌。 microsoftonline.com/<tenant id> /oauth2/v2.0/token


标题:


" Content-Type :application / x-www-form-urlencoded"


正文: 


{" client_id":< CLIENT_ID>,


" client_secret":< CLIENT_SECRET>,


" scope" :< https://storage.azure.com/.default",


" grant_type" :" client_credentials"


}


2。创建文件系统,方法是将PUT请求发送到https://<存储帐户名称> .dfs.core.windows.net /<文件系统名称>?resource = filesystem


标题:


Content-Length :0


" x-ms-version":" 2018-11-09"


授权:Bearer< access_token from step1>


3。通过向   https://<存储帐户名称> .dfs.core.windows.net /<文件系统名称>?action = setAccessControl

$发送PATCH请求,在根目录上设置默认权限b $ b

标题:


内容长度:0


" x-ms-version":" 2018-11-09"


授权:承载< access_token从step1>


x-ms-acl:
user :: rwx,group :: rx,other :: --x,默认值:user :: rwx,默认值:group :: rx,默认值:other :: -


4.
通过向https://<存储帐户名称> .dfs.core.windows.net /<存储PUT请求创建目录文件系统名称> /<目录名称>?resource =目录


标题:


内容长度:0


" x-ms-version":" 2018-11-09"


授权:Bearer< access_token from step1>


5.通过发出PUT请求来创建文件 https://<存储帐户名称> .dfs.core.windows.net /<文件系统名称> / <目录名称> /< file
name>?resource = file


标题:


内容长度:0


" x-ms-version":" 2018-11-09"


授权:承载< access_token从step1>


希望这会有所帮助。



I am trying to use the Rest API of Create path to create a file in ADLS Gen 2. The below are the parameters used for calling the API

https://<Accountname>.dfs.core.windows.net/<FileFolder Name>/test1.zip?resource=file&<SAS Token>

I have set the headers 

content-length:0
x-ms-version:2018-11-09

Still this request continuously gives the error 

error": {
        "code": "ContentLengthMustBeZero",
        "message": "The Content-Length request header must be zero"

}

I am stuck on this for 2 days. Any help is much appreciated

I am able to call the List operations successfully

解决方案

Hi there,

To use the REST APIs of ADLS Gen2, you need authorization header as well. Also the URL has SAS token directly(not as a parameter). 

A simple way to use ADLS Gen2 APIs (Using OAuth2) to create a file would be :

1. Acquire an Access token by making a POST request to https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token

Headers :

"Content-Type: application/x-www-form-urlencoded"

Body : 

{"client_id": <CLIENT_ID>,

"client_secret": <CLIENT_SECRET>,

"scope" : "https://storage.azure.com/.default",

"grant_type" : "client_credentials"

}

2. Create a file system by making a PUT request to https://<storage account name>.dfs.core.windows.net/<file system name>?resource=filesystem

Headers :

Content-Length : 0

"x-ms-version":"2018-11-09"

Authorization : Bearer <access_token from step1>

3. Set default permissions on the root directory by making a PATCH request to  https://<storage account name>.dfs.core.windows.net/<file system name>?action=setAccessControl

Headers :

Content-Length : 0

"x-ms-version":"2018-11-09"

Authorization : Bearer <access_token from step1>

x-ms-acl : user::rwx,group::r-x,other::--x,default:user::rwx,default:group::r-x,default:other::--

4. Create a directory by making a PUT request to https://<storage account name>.dfs.core.windows.net/<file system name>/<directory name>?resource=directory

Headers :

Content-Length : 0

"x-ms-version":"2018-11-09"

Authorization : Bearer <access_token from step1>

5. Create a file by making a PUT request tohttps://<storage account name>.dfs.core.windows.net/<file system name>/<directory name>/<file name>?resource=file

Headers :

Content-Length : 0

"x-ms-version":"2018-11-09"

Authorization : Bearer <access_token from step1>

Hope this helps.


这篇关于调用ADLS Gen 2 Rest API创建文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆