Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我如何使用租户id、客户端id和客户端机密来连接和管理Azure Data Lake Storage Gen2中的目录和文件?_Java_Azure_Spring Boot_Azure Storage - Fatal编程技术网

Java 我如何使用租户id、客户端id和客户端机密来连接和管理Azure Data Lake Storage Gen2中的目录和文件?

Java 我如何使用租户id、客户端id和客户端机密来连接和管理Azure Data Lake Storage Gen2中的目录和文件?,java,azure,spring-boot,azure-storage,Java,Azure,Spring Boot,Azure Storage,我想上传azure blob存储gen2中的文件。但问题是无法使用租户id、客户端id和客户端机密进行连接。我指的是文档->中给出的Java代码 但在上述代码的最后一行获取端点时出错 邮递员发信: URI http://localhost:8081/upload/ Request param : <file to be uploaded> "error": "Internal Server Error", "message"

我想上传azure blob存储gen2中的文件。但问题是无法使用租户id、客户端id和客户端机密进行连接。我指的是文档
->
中给出的Java代码

但在上述代码的最后一行获取端点时出错

邮递员发信:

URI http://localhost:8081/upload/
Request param : <file to be uploaded>

"error": "Internal Server Error",
"message": "java.lang.NoClassDefFoundError: com/azure/core/implementation/util/ImplUtils"
URIhttp://localhost:8081/upload/
请求参数:
“错误”:“内部服务器错误”,
“消息”:“java.lang.NoClassDefFoundError:com/azure/core/implementation/util/ImplUtils”

如果您想访问Azure data lake gen2 vai Azure AD auth,我们需要为sp或用户分配一个特殊的Azure RABC角色(
存储Blob数据所有者
存储Blob数据贡献者
存储Blob数据读取器
)。有关更多详细信息,请参阅

比如说

  • 创建服务主体并在存储帐户级别将
    存储Blob Data Contributor
    分配给sp
  • az登录
    az ad sp为rbac创建-n“MyApp”--角色“存储Blob数据贡献者”\
    --作用域/订阅//资源组//提供程序/Microsoft.Storage/storageAccounts/
    
  • 代码(下载文件)
  • String clientId=“”;
    字符串ClientSecret=“”;
    字符串tenantID=“”;
    ClientSecretCredential ClientSecretCredential=new ClientSecretCredentialBuilder()
    .clientId(clientId)
    .clientSecret(clientSecret)
    .tenantId(tenantId)
    .build();
    字符串accountName=“”;
    DataLakeServiceClient serviceClient=新DataLakeServiceClientBuilder()
    .credential(clientSecretCredential)
    .endpoint(“https://“+accountName+”.dfs.core.windows.net”)
    .buildClient();
    DataLakeFileSystemClient fileSystemClient=serviceClient.getFileSystemClient(“测试”);
    DataLakeFileClient fileClient=fileSystemClient.getFileClient(“test.txt”);
    ByteArrayOutputStream outputStream=新建ByteArrayOutputStream();
    fileClient.read(outputStream);
    字节[]数据=outputStream.toByteArray();
    System.out.println(“文件内容:+新字符串(数据));
    

    似乎有一些问题是由于SAS令牌错误来自DataLakeServiceClientBuilder::endpoint(),但不确定原因!!!如果它对你有用的话,你可以吗?你好,吉姆,我正试图从邮递员工具测试这个,但是得到了401授权。需要添加一些密钥吗?这可以从代码中处理吗?如何对端点进行身份验证,然后上载或下载文件?@javageekssb,关于此问题,您可以使用Azure AD客户端凭据流获取令牌,然后使用令牌调用Azure blob rest API。有关更多详细信息,请参阅和
    URI http://localhost:8081/upload/
    Request param : <file to be uploaded>
    
    "error": "Internal Server Error",
    "message": "java.lang.NoClassDefFoundError: com/azure/core/implementation/util/ImplUtils"
    
    az login
    az ad sp create-for-rbac -n "MyApp" --role 'Storage Blob Data Contributor' \
        --scopes /subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>
    
    String clientId="<sp appId>";
            String ClientSecret="<sp password>";
            String tenantID="";
            ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
                    .clientId(clientId)
                    .clientSecret(ClientSecret)
                    .tenantId(tenantID)
                    .build();
            String accountName="";
            DataLakeServiceClient serviceClient  = new DataLakeServiceClientBuilder()
                     .credential(clientSecretCredential)
                     .endpoint("https://" + accountName + ".dfs.core.windows.net")
                    .buildClient();
    
            DataLakeFileSystemClient fileSystemClient =serviceClient.getFileSystemClient("test");
            DataLakeFileClient fileClient = fileSystemClient.getFileClient("test.txt");
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            fileClient.read(outputStream);
            byte[] data =outputStream.toByteArray();
            System.out.println("The file content : "+new String(data));