Upload Contents to Azure Blob

Uploading files made easy.

Package Content

class azblobexplorer.AzureBlobUpload(account_name: str, account_key: str, container_name: str)[source]

Bases: azblobexplorer.base.BlobBase

Upload a file or a folder.

generate_url(blob_name: str, read: bool = True, add: bool = False, create: bool = False, write: bool = False, delete: bool = False, sas: bool = False, access_time: int = 1) → str

Generate’s blob URL. It can also generate Shared Access Signature (SAS) if sas=True.

Parameters
  • write (bool) –

    Write access

    New in version 2.0.

  • create (bool) –

    Create access

    New in version 2.0.

  • add (bool) –

    Add access

    New in version 2.0.

  • read (bool) –

    Read access

    New in version 2.0.

  • delete (bool) –

    Delete access

    New in version 2.0.

  • access_time (int) – Time till the URL is valid

  • blob_name (str) – Name of the blob, this could be a path

  • sas (bool) – Set True to generate SAS key

Returns

Blob URL

Example without ``sas``

>>> import os
>>> from azblobexplorer import AzureBlobDownload
>>> az = AzureBlobDownload('account name', 'account key', 'container name')
>>> az.generate_url("filename.txt")
https://containername.blob.core.windows.net/blobname/filename.txt

Example with ``upload_to`` and ``sas``

>>> import os
>>> from azblobexplorer import AzureBlobDownload
>>> az = AzureBlobDownload('account name', 'account key', 'container name')
>>> az.generate_url("filename.txt", sas=True)
https://containername.blob.core.windows.net/blobname/filename.txt?se=2019-11-05T16%3A33%3A46Z&sp=w&sv=2019-02-02&sr=b&sig=t%2BpUG2C2FQKp/Hb8SdCsmaZCZxbYXHUedwsquItGx%2BM%3D
generate_url_mime(blob_name: str, mime_type: str, sas: bool = False, read: bool = True, add: bool = False, create: bool = False, write: bool = False, delete: bool = False, access_time: int = 1) → str

Generate’s blob URL with MIME type. It can also generate Shared Access Signature (SAS) if sas=True.

Parameters
  • write (bool) –

    Write access

    New in version 2.0.

  • create (bool) –

    Create access

    New in version 2.0.

  • add (bool) –

    Add access

    New in version 2.0.

  • read (bool) –

    Read access

    New in version 2.0.

  • delete (bool) –

    Delete access

    New in version 2.0.

  • access_time (int) – Time till the URL is valid

  • blob_name (str) – Name of the blob

  • access_time – Time till the URL is valid

  • mime_type (str) – MIME type of the application

  • sas (bool) – Set True to generate SAS key

Returns

Blob URL

>>> import os
>>> from azblobexplorer import AzureBlobDownload
>>> az = AzureBlobDownload('account name', 'account key', 'container name')
>>> az.generate_url_mime("filename.zip", sas=True, mime_type="application/zip")
https://containername.blob.core.windows.net/blobname/filename.zip?se=2019-11-05T16%3A33%3A46Z&sp=w&sv=2019-02-02&sr=b&sig=t%2BpUG2C2FQKp/Hb8SdCsmaZCZxbYXHUedwsquItGx%2BM%3D
upload_file(file_path: str, upload_to: str = None, timeout: int = 10)[source]

Upload a file to a given blob path.

Parameters
  • upload_to (str) – Give the path to upload.

  • file_path (str) – Absolute path of the file to upload.

  • timeout (int) –

    Request timeout in seconds

    New in version 2.0.

>>> from azblobexplorer import AzureBlobUpload
>>> import os
>>> az = AzureBlobUpload('account name', 'account key', 'container name')
>>> here = os.path.abspath(os.path.dirname(__file__)) + os.sep
>>> az.upload_file(os.path.join(here, 'file1.txt'), 'blob_folder/')
upload_files(files_path: List[str], timeout: int = 10)[source]

Upload a list of files.

Parameters
  • files_path (list(str)) – A list of files to upload.

  • timeout (int) –

    Request timeout in seconds

    New in version 2.0.

>>> import os
>>> from azblobexplorer import AzureBlobUpload
>>> az = AzureBlobUpload('account name', 'account key', 'container name')
>>> here = os.path.abspath(os.path.dirname(__file__)) + os.sep
>>> path_list = [
...     [os.path.join(here, 'file1.txt'), 'folder_1/'],
...     [os.path.join(here, 'file2.txt'), 'folder_2/'],
...     os.path.join(here, 'file3.txt')
... ]
>>> az.upload_files(path_list)
upload_folder(folder_path: str, upload_to: str = None, timeout: int = 10)[source]

Upload a folder to a given blob path.

Parameters
  • upload_to (str) – Give the path to upload. Default None.

  • folder_path (str) – Absolute path of the folder to upload.

  • timeout (int) –

    Request timeout in seconds

    New in version 2.0.

Example without “upload_to”

>>> import os
>>> from azblobexplorer import AzureBlobUpload
>>> here = os.path.abspath(os.path.dirname(__file__)) + os.sep
>>> az = AzureBlobUpload('account name', 'account key', 'container name')
>>> az.upload_folder(os.path.join(here, 'folder_name'))

Example with “upload_to”

>>> import os
>>> from azblobexplorer import AzureBlobUpload
>>> here = os.path.abspath(os.path.dirname(__file__)) + os.sep
>>> az = AzureBlobUpload('account name', 'account key', 'container name')
>>> az.upload_folder(os.path.join(here, 'folder_name'), upload_to="my/blob/location/")