Write html file to azur blob storage with content type text/html

SaschaS
SaschaS Registered Posts: 12 ✭✭✭✭
edited July 16 in Using Dataiku

Hello,
I am trying to write an html file with the help of a python recipe into a folder which is located on a blog storage.
The writing works so far, but unfortunately the content type of the file is not text/html, but application/octet-stream.
In the Element folder in Dataiku I have set the Content Type to text/html under Settings, but unfortunately this seems to be ignored.
Is there a way to do this?

def write_to_folder(html, lang):
    # Write recipe outputs

    # Read recipe inputs
    manuals_html = dataiku.Folder("manuals_html")
    


    with manuals_html.get_writer("html_" + lang + ".html") as w:
        w.write(html.encode(encoding='UTF-8'))
        print('done')

Thanks
Sascha


Operating system used: Unix

Best Answer

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
    Answer ✓

    In that case the content type must be set by the APIs Dataiku is using to write the object. You will either need to call the Azure Blob APIs directly so you can have full control of the save file call or do an additional context type change call to change after Dataiku writes.

    Can you explain your requirement in detail? There might be a better way of doing this.

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
    edited July 17

    You need to use the folder.upload_stream() method:

    import dataiku
    managed_folder = dataiku.Folder('Landing')
    html_data = """<!DOCTYPE html>
    <html>
    <body>
    <h1>Heading</h1>
    <p>Paragraph</p>
    </body>
    </html>"""
    managed_folder.upload_stream("my_file.html", html_data)

    Screenshot 2024-02-02 at 11.57.23.png

  • SaschaS
    SaschaS Registered Posts: 12 ✭✭✭✭

    Hi,
    thanks for the help.
    I just tried this and unfortunately the Content Type on the Azure Blob Storage is set back to application/octet-stream.
    However, I need text/html there.

    Best regards
    Sascha

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron

    Keep in mind that the content type is not a property of the file, files have no content type. They can be text files or binary files, that's about it. So if the file is still being written as a text file then the issue is with the Azure Blob object content type.

Setup Info
    Tags
      Help me…