如何在 Azure Function 中包含非 python 参考文件?
How to include non-python reference files in Azure Function?
我有一些引用外部 .ttf
字体文件的 Python 代码。我可以通过将它们包含在项目根文件夹中来引用它们。我想将此代码转换为 HTTP 触发的 Azure 函数。
我看到 in the docs 我可以将外部 Python 模块和文件导入函数,但是 非Python 个文件?
这些是如何引用的?
- 当 Python 代码在本地 运行 时,它们在代码中被引用为:
h1_font = ImageFont.truetype("DejaVuSans-Bold.ttf", h1_size)
h2_font = ImageFont.truetype("Ubuntu-Th.ttf", h2_size)
h3_font = ImageFont.truetype("Ubuntu-Th.ttf", h3_size)
footer_font = ImageFont.truetype("UbuntuMono-R.ttf", footer_size)
应用发布到Azure时的文件路径是什么?
- 文件夹在本地的结构如下:
发布到 Azure 后,.ttf
文件将无法再访问且功能失败
注意:这是Python函数运行在Linux上,而不是Windows。
更新:
我的结构:
__init__.py
import logging
import azure.functions as func
from fontTools.ttLib import TTFont
def main(req: func.HttpRequest) -> func.HttpResponse:
font = TTFont('HttpTrigger1/font.ttf')
with open('HttpTrigger1/test.txt', 'r') as file:
data = file.read()
return func.HttpResponse("The content is -----------------"+data)
原答案:
How are these referenced?
放在Project文件夹下,使用相对路径。然后像以前一样使用它。
What is the filepath?
azure function app 的物理路径是D:\home\site\wwwroot
.
Do I just include them in the root folder of the Function and publish?
是的,将它们包含在根文件夹中,然后发布功能应用程序,然后您可以使用相对路径来获取它们。
我有一些引用外部 .ttf
字体文件的 Python 代码。我可以通过将它们包含在项目根文件夹中来引用它们。我想将此代码转换为 HTTP 触发的 Azure 函数。
我看到 in the docs 我可以将外部 Python 模块和文件导入函数,但是 非Python 个文件?
这些是如何引用的?
- 当 Python 代码在本地 运行 时,它们在代码中被引用为:
h1_font = ImageFont.truetype("DejaVuSans-Bold.ttf", h1_size)
h2_font = ImageFont.truetype("Ubuntu-Th.ttf", h2_size)
h3_font = ImageFont.truetype("Ubuntu-Th.ttf", h3_size)
footer_font = ImageFont.truetype("UbuntuMono-R.ttf", footer_size)
应用发布到Azure时的文件路径是什么?
- 文件夹在本地的结构如下:
发布到 Azure 后,.ttf
文件将无法再访问且功能失败
注意:这是Python函数运行在Linux上,而不是Windows。
更新:
我的结构:
__init__.py
import logging
import azure.functions as func
from fontTools.ttLib import TTFont
def main(req: func.HttpRequest) -> func.HttpResponse:
font = TTFont('HttpTrigger1/font.ttf')
with open('HttpTrigger1/test.txt', 'r') as file:
data = file.read()
return func.HttpResponse("The content is -----------------"+data)
原答案:
How are these referenced?
放在Project文件夹下,使用相对路径。然后像以前一样使用它。
What is the filepath?
azure function app 的物理路径是D:\home\site\wwwroot
.
Do I just include them in the root folder of the Function and publish?
是的,将它们包含在根文件夹中,然后发布功能应用程序,然后您可以使用相对路径来获取它们。