pythonazuredatabricksazure-storage-account

Save Docx in Azure Blob Storage using Databricks


i was trying to save a .docx file in azure storage account, but isn't working:

i did this:

Mounted the storage account:

storage_account_name = ""
storage_account_access_key = ""
container_name = "docs"
mount_point = "/mnt/my_mount_point" 

dbutils.fs.mount(
  source=f"wasbs://{container_name}@{storage_account_name}.blob.core.windows.net",
  mount_point=mount_point,
  extra_configs={f"fs.azure.account.key.{storage_account_name}.blob.core.windows.net": storage_account_key}
)

Try to save:

from docx import Document

doc = Document()

doc.add_heading('My Document Title', level=1)

temp_file_path = '/dbfs/tmp/docgerada.docx'

*doc.save(temp_file_path)*

destination_path = 'my_mount_point/new_document.docx'

dbutils.fs.cp('file:'+temp_file_path, f'/mnt/{destination_path}')

Get the error:

OSError: [Errno 95] Operation not supported

Solution

  • this works:

    doc.save('/databricks/teste.docx')
    
    destination_path = 'my_mount_point/doc.docx'
    
    dbutils.fs.cp('file:/databricks/teste.docx', f'/mnt/{destination_path}')