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

Solved!
SaschaS
Level 2
Write html file to azur blob storage with content type text/html

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

0 Kudos
1 Solution
Turribeach

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.

View solution in original post

0 Kudos
4 Replies
Turribeach

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

0 Kudos
SaschaS
Level 2
Author

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

 
0 Kudos
Turribeach

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.

0 Kudos
Turribeach

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. 

0 Kudos