首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Azure函数中处理POST请求以将文件上载到blob存储

在Azure函数中处理POST请求以将文件上载到blob存储
EN

Stack Overflow用户
提问于 2018-05-29 06:17:35
回答 1查看 2.4K关注 0票数 1

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

[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文件中,如下所示。

此外,我不知道使用content-type': 'application/octet-stream'在存储容器中创建blob是否只需要context.bindings.outputBlob = req.body;

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
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50573988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档