簡體   English   中英

從 Azure Function 獲取參數以用於 function.Z466DEEC76ECDF23456D38Zs 綁定71F6

[英]Getting parameters from an Azure Function to use in function.json bindings

I am new to Azure Functions and I'm having trouble with some of the basics, in particular how to pass parameter data to function.json so that I can write a blob to Azure Blob Storage using the Storage Connector.

我的問題是,如何在 httpTrigger function 中指定一個可由下面的 outputBlobContents 綁定使用的參數?

我的設置非常簡單(但還不行):


function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "blob",
      "direction": "out",
      "name": "outputBlobContents",
      "path": "uploaded_files/{destinationFilename}",
      "connection": "MY_STORAGE"
    }
  ]
}

index.ts

import { AzureFunction, Context, HttpRequest } from "@azure/functions"

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
    context.bindingData.destinationFilename = "testfile.pdf";
    context.bindings.outputBlobContents = context.req.body;
    const responseMessage = "uploaded file";

    context.res = {
        status: 201,
        body: responseMessage
    };

};

export default httpTrigger;

在我的示例代碼中,我嘗試將destinationFilename分配給context.bindingData object,但這不起作用。 我已經閱讀了所有文檔,但對於 bindingData object 實際上是什么或命名參數的一般工作方式並不是很清楚。 如何告訴 blob 存儲連接器將文件存儲在哪里?

簡單地說,任何形式的 json 輸入都會作為參數獲得。 function里面是不可能的。 如果要在function內部使用,請選擇直接使用Azure存儲的sdk。

由於您使用 httptrigger,您可以發送 json 格式的請求正文,如下所示:

{
   "destinationFilename":"something"
}

之后,output綁定就可以拿到值了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM