我正在尝试使用 Blob 触发器在本地调试 Azure 函数。将图像文件上传到 Azure 时,我在本地运行的函数会收到触发器。
def main(blobin: func.InputStream, blobout: func.Out[bytes], context: func.Context):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {blobin.name}\n"
f"Blob Size: {blobin.length} bytes")
image_file = Image.open(blobin)
我的function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "blobin",
"type": "blobTrigger",
"direction": "in",
"path": "uploads/{name}",
"connection": "STORAGE"
},
{
"name": "blobout",
"type": "blob",
"direction": "out",
"path": "uploads/{blob_name}_resized.jpg",
"connection": "STORAGE"
}
]
}
Image.open(blobin)
线路运行时我得到的错误是:
System.Private.CoreLib:执行函数时出现异常:Functions.ResizePhoto。System.Private.CoreLib:结果:失败异常:UnidentifiedImageError:无法识别图像文件 <_io.BytesIO object at 0x0000017FD4FD7F40>
有趣的是,图像本身确实会在 VSCode 监视窗口中打开,但在运行代码时会失败。如果我再次将其添加到手表(可能会触发手表刷新),它也会给出与上述相同的错误。