Azure 是否允许将"hosted"文件的文件位置作为 URL 发送,以便在部署 Flask 应用时下载该文件?



注意:这更多的是一个研究问题,如果我认为这是一个糟糕的问题,听起来很愚蠢,我会申请。虽然我相信理论上这应该可行,但我不想冒险。

我有一个python flask web应用程序,它有一个完整的背景脚本(太长了,无法在这里解释(;背景";它生成一个ZIP文件,并使用sendGRID发送每个邮件的文件位置。简而言之,文件位置是作为标准html模板中的clickable_url发送的,该模板用作邮件本身。

send_grid_mail = 'Classified
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

def main(file_name: str,file_location:str, attachment_bool: bool, download_link:str, recipient_email: str):
file_path = file_location
if os.getenv('SENDGRID_API_KEY') == None:
print("No API KEY FOUND")
else:

print("API KEY FOUND")
html_string = generate_html_content(attachment_bool,download_link)
message = Mail(
from_email='Classified',
to_emails=recipient_email,
subject='Uw data is gereed.',
html_content= html_string)
if attachment_bool is True:
with open(file_path, 'rb') as f:
data = f.read()
f.close()
encoded_file = base64.b64encode(data).decode()
attachment = Attachment()
attachment.file_content = FileContent(encoded_file)
attachment.file_type = FileType('application/zip')
attachment.file_name = FileName('{}.zip'.format(file_name))
attachment.disposition = Disposition('attachment')
attachment.content_id = ContentId('Example Content ID')
message.attachment = attachment
try:     
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print("Failed scenario")
print("Scenerio checking")

# Generates the HTML variables for the email page.
def generate_html_content(attachment_bool: bool,download_link: str):
if attachment_bool is False:
Letter_1 = "Helaas was deze te groot om via mail door te sturen."
Letter_2 = "Klik hier om het bestand te downloaden."
if attachment_bool is True:
Letter_1 =  "U vindt het bestand terug in de bijlage."
Letter_2 = "Is het bestand niet in de bijlage terug te vinden? Klik dan hier en download dan hier."
return render_template(
'email.html',
message_1 = Letter_1,
message_2 = Letter_2,
link = download_link,
title='YOU GOT MAIL'
)
if __name__ == "__main__":
main()

发送邮件和链接本身工作。。。使用我设置的本地文件系统,所以我无法确认是否会有下载提示。

目前,这只是作为本地文件位置,所以我无法通过下载文件来测试它是否有效。

目前,文件的存储位置是一个名为DATA_DIR的本地系统变量,但它也已编程到Docker中。这只是"/数据";简单地说。

考虑到将来当该应用程序被部署到Azure时,它当然被存储在Web应用程序本身的文件夹中/数据";文件夹

但当它被部署到azure虚拟环境中以托管我们的web应用程序时,我怀疑这是否有效。

理论上,这将工作,因为文件,它是相同的原则,基于你如何制作网页。

你可以参考";本地";文件。所以我可能在找这个。现在我正在查看此Azure Blob存储。所以我一直在读这个。只是我有点担心安全问题。

有两种方法可以从云中获得文件:

  • 第一个来自连接到虚拟机的硬盘驱动器应用程序正在运行。要得到这些文件,绝对有与您的计算机或任何其他个人电脑。这里的不便,从云点当然,是您的文件可以在停止虚拟机时删除机器(取决于所附硬盘驱动器上的策略(
  • 第二种选择是使用Azure Blob存储(如果您在AWS,则使用AWS S3;如果您在GCP,则使用谷歌云存储(。此托管服务允许您存储具有高可用性和>99%的SLA。停止和/或删除虚拟机不会影响存储的数据。这里的不便之处在于,您必须调整代码以与此托管服务对话,而不是在硬盘中查找文件(https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python)

最新更新