我正试图写一个API上传文件到我的adls 2存储。
下面的代码片段
var credential = new Azure.Identity.DefaultAzureCredential();
var fileSystemClient = new DataLakeFileSystemClient(new Uri("https://mystorageaccount.dfs.core.windows.net"), credential);//_applicationSettings?.ObjectStoreSettings?.Uri
DataLakeFileClient fileClient = fileSystemClient.GetFileClient($@"general\landing\{objectPushRequest.File.Name}");
using (Stream fileStream = objectPushRequest.File.OpenReadStream())
{
// Upload the file asynchronously
await fileClient.UploadAsync(fileStream, true);
message = BuildMessage(Status.Success, ErrorCodes.NoError, "Object Push service uploaded file to Blob");
return (message, null);
}
但当我执行上述代码,我得到无效的uri错误
Azure.RequestFailedException:请求URI无效。RequestId:a2504662- 501 f-0060-0145- 6ccc 0 c 000000时间:2023-04- 11 T07:17:10.8515000Z状态:400(请求的URI无效。)ErrorCode:InvalidUri
内容:{“error”:{“code”:“InvalidUri”,“message”:“请求URI无效。\nRequestId:a2504662- 501 f-0060-0145-6ccc0c000000\nTime:2023-04- 11 T07:17:10.8515000Z”}}
但是上面的dfs URL是从Azure门户本身复制的。
所以我不明白我做错了什么!请帮助
1条答案
按热度按时间gab6jxml1#
查看示例代码片段和错误消息,很明显失败是由于
Invalid Request URL
。您可以利用以下示例代码将文件上传到ADLS Gen 2 Storage:
More Info here . Hope this helps.