1
votes

I'm trying to upload a file via simple Azure function HTTPTrigger in JS and it gives me the following error:

[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.

I'm not sure where to find and edit the .config file or add an environment variable. The connection string is already added to the function.json file as seen below.

Also, I don't know whether just context.bindings.outputBlob = req.body; is enough to create a blob in the storage container with 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
}
1
Your code is enough to create a blob, and @Evandro has provided a nice answer for your connection string problem.Jerry Liu

1 Answers

1
votes

Navigate to the Azure Portal > Your Azure Function App > Platform Features > Application Settings and add the Storage Account connection string as a value and the SOME CONNECTION STRING string in your function.json file as the name.

You can add it as an Application Setting or a custom Connection String, either will work fine.

Find more details at https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node.