0

I have a Python application which creates a HTML file which I then want to upload to an Azure Web Application.

What is the best way to do this?

I originally started try to do it using FTP and then switched to pushing with GIT. None of these really felt right. How should I be doing this?

UPDATE

I have this 99% working. I'm using a Storage Account to host a static site (which feels like the right way to do this).

This is how I am uploading:

        blob_service_client = BlobServiceClient.from_connection_string(az_string)
        # Create a blob client using the local file name as the name for the blob
        blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)

        print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)

        # Upload the created file
        with open('populated.html', "rb") as data:
            blob_client.upload_blob(data)

The only problem that I have now, is that the file is downloading instead of opening in the browser. I think I need to set the content type somewhere.

Update 2 Working now, I added:

my_content_settings = ContentSettings(content_type='text/html')

test = blob_client.upload_blob(data, overwrite=True, content_settings=my_content_settings)

Cheers,

Mick

3

1 Answer 1

1

The best way to do this is up to you.

Generally, there are two ways to upload a HTML file to Azure Web App for Windows, as below.

  1. Following the Kudu wiki page Accessing files via ftp to upload a file via FTP.
  2. Following the sections VFS, Zip and Zip Deployment of Kudu wiki page REST API to call the related PUT REST API to upload a file via HTTP client.

However, based on my understanding for your scenario, the two ways above are not simple. So I recommanded to use the feature Static website of Azure Blob Storage Gen 2 to host your static HTML file generated by your Python application and to upload files via Azure Storage SDK for Python. I think it's simple enough to you, even you can bind a custom domain to the default host name of static website of Azure Blob Storage via DNS CNAME.

The steps are below.

  1. Refer to the offical document Host a static website in Azure Storage to create an account of Azure Blob Storage Gen 2 and enable the feature Static website.

  2. Refer to the other offical document Quickstart: Azure Blob storage client library v12 for Python to write the code for uploading in your current Python application . The container default named $web is for hosting static website, you just need to upload the files to it, then access its primary endpoint as the figure from offical document below to see it.

    enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

OK, I will give this a go. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.