gpt4 book ai didi

azure - 我们可以使用 blob 绑定(bind)器将文件上传到 Azure 数据湖第 2 代吗

转载 作者:行者123 更新时间:2023-12-03 04:56:40 24 4
gpt4 key购买 nike

我知道我们可以使用 .net sdk 管理 ADL 第 2 代中的文件,如下文所述 https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-dotnet

我只是想知道我们是否也可以在 ADLS gen 2 中使用诸如 cloudBlockBlob 之类的绑定(bind)器,就像在常规 Azure 存储帐户中一样。

最佳答案

经过测试,cloudBlockBlob绑定(bind)可以在ADLs gen 2中使用。

我使用此代码将文件上传到adls2帐户:

using System;
using Azure;
using Azure.Storage.Files.DataLake;
using Azure.Storage.Files.DataLake.Models;
using Azure.Storage;
using System.IO;

namespace Frankadls
{
class Program
{
static async System.Threading.Tasks.Task Main(string[] args)
{
Console.WriteLine("Hello World!");
string accountName = "";
string accountKey = "";
StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);

string dfsUri = "https://" + accountName + ".dfs.core.windows.net";

DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient(new Uri(dfsUri), sharedKeyCredential);
DataLakeFileSystemClient dataLakeFileSystemClient = await dataLakeServiceClient.CreateFileSystemAsync("test1");
DataLakeDirectoryClient directoryClient = await dataLakeFileSystemClient.CreateDirectoryAsync("my-directory");
DataLakeFileClient fileClient = await directoryClient.CreateFileAsync("uploaded-file.txt");

FileStream fileStream = File.OpenRead("");

long fileSize = fileStream.Length;

await fileClient.AppendAsync(fileStream, offset: 0);

await fileClient.FlushAsync(position: fileSize);
}
}
}

这段代码。使用cloudBlockBlob输入绑定(bind),可以成功触发:

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;

namespace Frankblobtrigger
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([BlobTrigger("test1/{name}", Connection = "conn")]Stream myBlob, string name,
[Blob("test1/{name}", FileAccess.Read, Connection = "conn")] CloudBlockBlob blob,
ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
log.LogInformation(blob.Uri.AbsoluteUri);
}
}
}

enter image description here

关于azure - 我们可以使用 blob 绑定(bind)器将文件上传到 Azure 数据湖第 2 代吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67492280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com