繁体   English   中英

如何获取 c# 脚本 Azure function 以读取文件从 Z0D61F8370CAD1D412F5ZE4 驱动器读取文件?

[英]How to get an c# script Azure function to read a file from C drive, write to blob storage?

I need a c# script Azure function to read a file from the C drive, and write it to a blob storage account. 我想我对如何编写文件有所了解,但是如何阅读它呢?

I'm a powershell guy trying to understand functions, go easy on me, I'm imagining a web page which allows selection of a file on the C drive: containing something like:

<label for="Image">Select the image file to upload: </label><input type="file" name="Image" />. 

用户选择一个文件,然后单击一个链接,该链接是一个 http 触发器,用于 Azure function 将文件上传到 blob 存储帐户。

如果这是合理的,我需要获取 function 来读取 C 驱动器上的文件。 我已经阅读了一些 c# 指南,我正在尝试使用 c# 脚本,因为它似乎比 c# 的学习曲线要少。 通过从演示 http 触发器 function 复制代码并添加一些我在谷歌上搜索到的代码,我取得了一些进展。 因此,例如,此代码将一些文本写入 blob:

#r "Newtonsoft.Json"
#r "Microsoft.AspNetCore.Mvc"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
//added by me
using Microsoft.Azure.Storage.Blob;
using Microsoft.Azure.Storage;

public static async Task<IActionResult> Run(HttpRequest req, TextWriter myOutputBlob, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    // I think we're using the Namespace: Microsoft.AspNetCore.Http
    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;
    myOutputBlob.Write(name);

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

我想我需要将MyOutputBlob的类型更改为ZF7B44CFAFD5C52222222222223D5498196C8A2E7BZ,我想我可能能够通过编写ZF7B44CFAFD5222222222222223D5498196C8A2E7BZ TORE of PLOINE FARE MATE to not the the n.bob the nody y sobib of Blob,但是.

例如,我认为我从演示中复制的 HttpRequest class(用于 req 参数)来自 Microsoft.AspNetCore.Http 命名空间,但这似乎只有几个方法和属性,而且我看不到任何看起来像它的东西打算读取我的 C 驱动器上的文件。

我将不胜感激任何解释,任何代码,任何能让我走得更远的东西。 请记住,我不会理解针对 c# 开发人员级别的人的东西!

如果相关,这是我的 function.json 文件:

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "name": "myOutputBlob",
      "type": "blob",
      "path": "myfolder/myBlob-%myValue%-{rand-guid}.txt",
      "connection": "",
      "direction": "out"
    }
  ]
}

对于您提到的用例,我没有 Azure Function 和 C# 示例代码,但是,我可以为您提供帮助。 请PM我。

您是否也考虑过使用 Azure 数据工厂将数据复制到 Azure Blob 存储或从中复制数据? 或者,您可以评估此解决方案

Aung Oo, Microsoft Azure 存储工程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM