How Do I get the Name of The inputBlob That Trigge

2020-07-03 04:27发布

I have an azure function which is triggered by a file being put into blob storage and I was wondering how (if possible) to get the name of the blob (file) which triggered the function, I have tried doing:

fileObject=os.environ['inputBlob']
message = "Python script processed input blob'{0}'".format(fileObject.fileName)

and

fileObject=os.environ['inputBlob']
message = "Python script processed input blob'{0}'".format(fileObject.name)

but neither of these worked, they both resulted in errors. Can I get some help with this or some suggesstions?

Thanks

4条回答
\"骚年 ilove
2楼-- · 2020-07-03 05:02

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"
    }
  ],
}
查看更多
forever°为你锁心
3楼-- · 2020-07-03 05:04

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)
查看更多
The star\"
4楼-- · 2020-07-03 05:06

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.

查看更多
趁早两清
5楼-- · 2020-07-03 05:18

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

查看更多
登录 后发表回答