簡體   English   中英

如何從 .NET 在 Azure Data Lake 文件共享中創建文件?

[英]How can I create files in Azure Data Lake File Shares from .NET?

我一直在嘗試在 Azure Data Lake Gen2 文件共享中創建一個目錄。 我可以使用下面的代碼在同一個存儲帳戶中創建一個 blob 容器而不會出錯。

        static void Main(string[] args)
        {
            string storageUri = "https://xxxxxxx.dfs.core.windows.net";
            DefaultAzureCredential cred = new DefaultAzureCredential();
            DataLakeServiceClient serviceClient = new DataLakeServiceClient(new Uri(storageUri), cred);
            DataLakeFileSystemClient fileSystem = serviceClient.CreateFileSystem("test");
        }

如何創建文件共享目錄而不是 blob 容器? 我試過使用xxxxxxx.file.core.windows.net而不是 dfs,但得到一個錯誤AuthenticationErrorDetail: Authentication scheme Bearer is not supported for Files.

這個來自 Azure Storage Eplorer 的片段展示了我的意思。

存儲資源管理器截圖

我需要使用不同的 API 嗎? 不同的認證? 感謝您提供任何幫助。

這個示例滿足了我的需求。

        static void Main(string[] args)
        {
            string storageUri = "https://xxxxxx.file.core.windows.net/myshare";
            string sas = "SAS credential to file share xxxxxx.file.core.windows.net/myshare. SAS must include create privilege.";

            AzureSasCredential cred = new AzureSasCredential(sas);
            ShareClient shareClient = new ShareClient(new Uri(storageUri), cred);
            Response<ShareDirectoryClient> resp = shareClient.CreateDirectory("test");
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM