如何在Azure Function中包含非python参考文件? [英] How to include non-python reference files in Azure Function?

查看:45
本文介绍了如何在Azure Function中包含非python参考文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Python代码引用了外部 .ttf 字体文件.我可以通过将它们包含在项目根文件夹中来引用它们.我想将此代码转换为HTTP触发的Azure函数.

我在文档中看到

一旦发布到Azure, .ttf 文件将不再可访问并且功能失败

注意:这是在Linux而非Windows上运行的Python函数.

解决方案

更新:

我的结构:

__ init __.py

 导入日志记录将azure.functions导入为func从fontTools.ttLib导入TTFontdef main(req:func.HttpRequest)->func.HttpResponse:字体= TTFont('HttpTrigger1/font.ttf')使用open('HttpTrigger1/test.txt','r')作为文件:数据= file.read()return func.HttpResponse(内容为-----------------""+ data" 

原始答案:

这些如何引用?

将其放在Project文件夹中,并使用相对路径.然后像以前一样使用它.

什么是文件路径?

天蓝色功能应用程序的物理路径为 D:\ home \ site \ wwwroot .

我是否只将它们包含在函数的根文件夹中并发布?

是的,只需将它们包含在根文件夹中,然后发布功能应用程序,然后就可以使用相对路径来获取它们.

I have some Python code that references external .ttf font files. I can reference them by including them in the project root folder. I'd like to turn this code into an HTTP Triggered Azure Function.

I see in the docs that I can import external Python modules and files into a Function, but what about non-Python files?

How are these referenced?

  • When Python code is run locally, they are referenced in the code as:

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)

What is the filepath when the app is published to Azure?

  • Here is how the folders are structured locally:

Once published to Azure, the .ttf files are no longer accessible and Function fails

Note: This is a Python Function running on Linux, not Windows.

解决方案

Update:

My structure:

__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)
    

Original Answer:

How are these referenced?

Put it in the Project folder and use relative path. Then use it as before.

What is the filepath?

Physical path of azure function app is D:\home\site\wwwroot.

Do I just include them in the root folder of the Function and publish?

Yes, just include them in the root folder and then publish the function app, and then you can use relative path to get them.

这篇关于如何在Azure Function中包含非python参考文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆