How Do I get the Name of The inputBlob That Triggered My Azure Function With Python

允我心安 提交于 2019-12-03 23:54:26

The blob name can be captured via the Function.json and provided as binding data. See the {filename} token below. Function.json is language agnostic and works in all languages.

See documentation at https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings for details.

{
  "bindings": [
    {
      "name": "image",
      "type": "blobTrigger",
      "path": "sample-images/{filename}",
      "direction": "in",
      "connection": "MyStorageConnection"
    },
    {
      "name": "imageSmall",
      "type": "blob",
      "path": "sample-images-sm/{filename}",
      "direction": "out",
      "connection": "MyStorageConnection"
    }
  ],
}

There is not any information about what trigger you used in your description. But fortunately, there is a sample project yokawasa/azure-functions-python-samples on GitHub for Azure Function using Python which includes many samples using different triggers like queue trigger or blob trigger. I think it's very helpful for you now, and you can refer to these samples to write your own one to satisfy your needs。

Hope it helps.

Getting the name of the inputBlob is not currently possible with Python Azure-Functions. There are open issues about it in azure-webjobs-sdk and azure-webjobs-sdk-script GitHub:

https://github.com/Azure/azure-webjobs-sdk/issues/1090

https://github.com/Azure/azure-webjobs-sdk-script/issues/1339

Unfortunatelly it's still not possible. In Python, you can do:

import azure.functions as func
import os
def main(blobin: func.InputStream):
    filename=os.path.basename(blobin.name)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!