0
votes

I am using python Azure sdk. When the file uploaded its content type changed to application/octet-stream.

I want to set its default content type like image/png for PNG image.

I am using following method for upload the file put_block_blob_from_path()

is there any way to retain default content type? Thanks

2

2 Answers

5
votes

You can explicitly set the content-type property like this:

from azure.storage.blob import ContentSettings

block_blob_service.create_blob_from_path(
    'mycontainer',
    'myblockblob',
    'mypngimage.png',
    content_settings=ContentSettings(content_type='image/png')
)

Source: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-python-how-to-use-blob-storage

0
votes

Azure blob falls to the default value of 'application/octet-stream' if nothing is provided. To get the correct mimetypes, this is what I did with my flask app:

    @app.route('/', methods=['GET', 'POST'])
def upload_file():
        if request.method == 'POST':
            f = request.files['file']
            mime_type = f.content_type
            print (mime_type)
            print (type(f))
            try:
                blob_service.create_blob_from_stream(container, f.filename, f,
                content_settings=ContentSettings(content_type=mime_type))

mime_type was passed to ContentSettings to get the current mimetypes of files uploaded to azure blob.