public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            //connect to account
            string accountName    = Common.GetEnvironmentVariable("DataLakeAccountName");
            string accountKey     = Common.GetEnvironmentVariable("DataLakeAccountKey");
            string fileSystemName = Common.GetEnvironmentVariable("DataLakeFileSystemName");

            StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);

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

            DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient(new Uri(dfsUri), sharedKeyCredential);

            //upload file
            DataLakeFileSystemClient fileSystemClient = dataLakeServiceClient.GetFileSystemClient(fileSystemName);

            string             fileName   = Guid.NewGuid().ToString() + ".json";
            DataLakeFileClient fileClient = await fileSystemClient.CreateFileAsync(fileName);

            long fileSize = req.Body.Length;

            await fileClient.AppendAsync(req.Body, offset : 0);

            await fileClient.FlushAsync(position : fileSize);

            return((ActionResult) new OkResult());
        }
Exemple #2
0
 /// <summary>
 /// Creates new file.
 /// </summary>
 /// <param name="path">Path of folder to create new file.</param>
 /// <param name="name">Name of new file.</param>
 /// <returns></returns>
 public async Task CreateFileAsync(string path, string name)
 {
     if (path == "/")
     {
         await dataLakeClient.CreateFileAsync(name);
     }
     else
     {
         await GetDirectoryClient(path).CreateFileAsync(name);
     }
 }