简体   繁体   中英

Azure blob storage function using Python - Setting multiple output bindings is not working

This is the first time to use Azure and I am trying to make a pipeline using Azure. What I want to do is to make multiple outputblobs so that I can duplicate a file.

def main(inputblob: func.InputStream,
         outputblob_first: func.Out[func.InputStream],
         outputblob_second: func.Out[func.InputStream],
         outputblob_third: func.Out[func.InputStream]):
   
   outputblob_first.set(inputblob)
   outputblob_second.set(inputblob)
   outputblob_third.set(inputblob)

This is init.py.

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "inputblob",
      "type": "blobTrigger",
      "direction": "in",
      "dataType": "binary",
      "path": "blobcontainer/{name}",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputblob_first",
      "type": "blob",
      "path": "uploadblobcontainer/{blobtrigger}-first",
      "dataType": "binary",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    },
    {
      "name": "outputblob_second",
      "type": "blob",
      "path": "uploadblobcontainer/{blobtrigger}-second",
      "dataType": "binary",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    },
    {
      "name": "outputblob_third",
      "type": "blob",
      "path": "uploadblobcontainer/{blobtrigger}-third",
      "dataType": "binary",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
  ]
}

and this is the json file, function.json

However, it does not work what I expected. I could not find where I did mistake and I want to solve this problem. Can you guys give me some solutions?

When I test it for you, I get the following error message:

The 'BlobTrigger' function is in error: The binding name outputblob_first is invalid. Please assign a valid name to the binding.

在此处输入图像描述

I think you need to change your binding name. You can refer to my sample:

import logging
import azure.functions as func


def main(inputblob: func.InputStream,
        outputblob1: func.Out[func.InputStream],
        outputblob2: func.Out[func.InputStream],
        outputblob3: func.Out[func.InputStream]):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {inputblob.name}\n"
                 f"Blob Size: {inputblob.length} bytes")
    outputblob1.set(inputblob)
    outputblob2.set(inputblob)
    outputblob3.set(inputblob)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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