在Azure函数中处理POST请求以将文件上传到Blob存储?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (232)

我试图通过简单的Azure函数HTTPTrigger在JS中上传文件,它给了我以下错误:

[Error] Exception while executing function: Functions.HttpTriggerJS1. Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK '[Hidden Credential]' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:
1. Set the connection string named '[Hidden Credential]' in the connectionStrings section of the .config file in the following format <add name="[Hidden Credential]" connectionString="DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY" />, or
2. Set the environment variable named '[Hidden Credential]', or
3. Set corresponding property of JobHostConfiguration.

我不确定在哪里查找和编辑.config文件或添加环境变量。连接字符串已经添加到function.json文件中,如下所示。

另外,我不知道是否context.bindings.outputBlob = req.body; 足以在存储容器中创建一个blob content-type': 'application/octet-stream'

index.js:

module.exports = function (context, req) {

 context.log('JavaScript HTTP trigger function processed a request.');

 context.bindings.outputBlob = req.body;

 context.res = {

 // status: 200, /* Defaults to 200 */

 body: "Uploaded " 

 };

 context.done();

};

function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "FileUploadNode/{filename}",
      "methods": [
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "blob",
      "name": "outputBlob",
      "path": "CONTAINER-NAME/{filename}",
      "connection": "SOME CONNECTION STRING",
      "direction": "out"
    }
  ],
  "disabled": false
}
提问于
用户回答回答于

导航到Azure的门户网站>你Azure的功能应用>平台的特点>应用程序设置和添加存储帐户连接字符串的一些连接字符串在function.json文件作为字符串名称。

你可以将其作为应用程序设置或自定义连接字符串添加,也可以正常工作。

通过https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node 查找更多详细信息。

扫码关注云+社区

领取腾讯云代金券