0
votes

I know we can manage a file in ADLs gen 2 using .net sdk as mentioned in below article https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-dotnet

I just want to know if we can also use binders such as cloudBlockBlob too in ADLS gen 2 as we can in regular azure storage account.

2

2 Answers

2
votes

After testing, the cloudBlockBlob binding can be used in ADLs gen 2.

I use this code to upload files to the adls2 account:

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);
        }
    }
}

This code. Using the cloudBlockBlob input binding, it can be triggered successfully:

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

1
votes

Yes, for.net, just use blob output binding. And you should be able to use cloudblockblob to upload.