How to use azure-storage-file - 10 common examples

To help you get started, we’ve selected a few azure-storage-file examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
When this is set to True and specified together with the Range header, 
            the service returns the MD5 hash for the range, as long as the range 
            is less than or equal to 4 MB in size.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :param str snapshot:
            A string that represents the snapshot version, if applicable.
        :return: A File with content, properties, and metadata.
        :rtype: :class:`~azure.storage.file.models.File`
        '''
        _validate_not_none('share_name', share_name)
        _validate_not_none('file_name', file_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name, directory_name, file_name)
        request.query = {'timeout': _int_to_str(timeout), 'sharesnapshot': _to_str(snapshot)}
        _validate_and_format_range_headers(
            request,
            start_range,
            end_range,
            start_range_required=False,
            end_range_required=False,
            check_content_md5=validate_content)

        return self._perform_request(request, _parse_file,
                                     [file_name, validate_content],
                                     operation_context=_context)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
:param int max_results:
            Specifies the maximum number of shares to return. A single list
            request may return up to 1000 shares and potentially a continuation
            token which should be followed to get additional resutls.
        :param string include:
            Include this parameter to specify that either the share's
            metadata, snapshots or both be returned as part of the response body. set this
            parameter to string 'metadata' to get share's metadata. set this parameter to 'snapshots'
            to get all the share snapshots. for both use 'snapshots,metadata'.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host_locations = self._get_host_locations()
        request.path = _get_path()
        request.query = {
            'comp': 'list',
            'prefix': _to_str(prefix),
            'marker': _to_str(marker),
            'maxresults': _int_to_str(max_results),
            'include': _to_str(include),
            'timeout': _int_to_str(timeout),
        }

        return self._perform_request(request, _convert_xml_to_shares, operation_context=_context)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
its files, its subdirectories and their files.
        :param str handle_id:
            Required. Specifies handle ID opened on the file or directory to be closed.
            Astrix (‘*’) is a wildcard that specifies all handles.
        :param str marker:
            Specifies the maximum number of handles taken on files and/or directories to return.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :param str snapshot:
            A string that represents the snapshot version, if applicable.
        """
        _validate_not_none('share_name', share_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name, directory_name, file_name)
        request.query = {
            'comp': 'forceclosehandles',
            'marker': _to_str(marker),
            'timeout': _int_to_str(timeout),
            'sharesnapshot': _to_str(snapshot)
        }
        request.headers = {
            'x-ms-recursive': _to_str(recursive),
            'x-ms-handle-id': _to_str(handle_id),
        }

        return self._perform_request(request, _parse_close_handle_response, operation_context=_context)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
statistics grouped by API in hourly aggregates for files.
        :param Metrics minute_metrics:
            The minute metrics settings provide request statistics 
            for each minute for files.
        :param cors:
            You can include up to five CorsRule elements in the 
            list. If an empty list is specified, all CORS rules will be deleted, 
            and CORS will be disabled for the service.
        :type cors: list(:class:`~azure.storage.common.models.CorsRule`)
        :param int timeout:
            The timeout parameter is expressed in seconds.
        '''
        request = HTTPRequest()
        request.method = 'PUT'
        request.host_locations = self._get_host_locations()
        request.path = _get_path()
        request.query = {
            'restype': 'service',
            'comp': 'properties',
            'timeout': _int_to_str(timeout),
        }
        request.body = _get_request_body(
            _convert_service_properties_to_xml(None, hour_metrics, minute_metrics, cors))

        self._perform_request(request)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
:param str share_name:
            Name of existing share.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :param str snapshot:
            A string that represents the snapshot version, if applicable.
        :return:
            A dictionary representing the share metadata name, value pairs.
        :rtype: dict(str, str)
        '''
        _validate_not_none('share_name', share_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name)
        request.query = {
            'restype': 'share',
            'comp': 'metadata',
            'timeout': _int_to_str(timeout),
            'sharesnapshot': _to_str(snapshot),
        }

        return self._perform_request(request, _parse_metadata)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
Name of existing share.
        :param str directory_name:
           The path to an existing directory.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :return: properties for the specified directory within a directory object.
        :param str snapshot:
            A string that represents the snapshot version, if applicable.
        :rtype: :class:`~azure.storage.file.models.Directory`
        '''
        _validate_not_none('share_name', share_name)
        _validate_not_none('directory_name', directory_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name, directory_name)
        request.query = {
            'restype': 'directory',
            'timeout': _int_to_str(timeout),
            'sharesnapshot': _to_str(snapshot)
        }

        return self._perform_request(request, _parse_directory, [directory_name])
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
Length of the file in bytes.
        :param ~azure.storage.file.models.ContentSettings content_settings:
            ContentSettings object used to set file properties.
        :param metadata:
            Name-value pairs associated with the file as metadata.
        :type metadata: dict(str, str)
        :param int timeout:
            The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('share_name', share_name)
        _validate_not_none('file_name', file_name)
        _validate_not_none('content_length', content_length)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name, directory_name, file_name)
        request.query = {'timeout': _int_to_str(timeout)}
        request.headers = {
            'x-ms-content-length': _to_str(content_length),
            'x-ms-type': 'file'
        }
        _add_metadata_headers(metadata, request)
        if content_settings is not None:
            request.headers.update(content_settings._to_headers())

        self._perform_request(request)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
share as metadata. Example:{'Category':'test'}
        :type metadata: dict(str, str):
        :param bool fail_on_exist:
            specify whether to throw an exception when the directory exists.
            False by default.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :return: True if directory is created, False if directory already exists.
        :rtype: bool
        '''
        _validate_not_none('share_name', share_name)
        _validate_not_none('directory_name', directory_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name, directory_name)
        request.query = {
            'restype': 'directory',
            'timeout': _int_to_str(timeout),
        }
        _add_metadata_headers(metadata, request)

        if not fail_on_exist:
            try:
                self._perform_request(request, expected_errors=_RESOURCE_ALREADY_EXISTS_ERROR_CODE)
                return True
            except AzureHttpError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
Note that this value may not include all recently created
        or recently re-sized files.

        :param str share_name:
            Name of existing share.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :return: the approximate size of the data stored on the share.
        :rtype: int
        """
        _validate_not_none('share_name', share_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host_locations = self._get_host_locations()
        request.path = _get_path(share_name)
        request.query = {
            'restype': 'share',
            'comp': 'stats',
            'timeout': _int_to_str(timeout),
        }

        return self._perform_request(request, _convert_xml_to_share_stats)
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / fileservice.py View on Github external
The path to a directory.
        :param str file_name:
            Name of a file.
        :param int timeout:
            The timeout parameter is expressed in seconds.
        :param str snapshot:
            A string that represents the snapshot version, if applicable.
        :return: A boolean indicating whether the resource exists.
        :rtype: bool
        '''
        _validate_not_none('share_name', share_name)
        try:
            request = HTTPRequest()
            request.method = 'HEAD' if file_name is not None else 'GET'
            request.host_locations = self._get_host_locations()
            request.path = _get_path(share_name, directory_name, file_name)

            if file_name is not None:
                restype = None
                expected_errors = [_RESOURCE_NOT_FOUND_ERROR_CODE, _PARENT_NOT_FOUND_ERROR_CODE]
            elif directory_name is not None:
                restype = 'directory'
                expected_errors = [_RESOURCE_NOT_FOUND_ERROR_CODE, _SHARE_NOT_FOUND_ERROR_CODE,
                                   _PARENT_NOT_FOUND_ERROR_CODE]
            else:
                restype = 'share'
                expected_errors = [_SHARE_NOT_FOUND_ERROR_CODE]

            request.query = {
                'restype': restype,
                'timeout': _int_to_str(timeout),
                'sharesnapshot': _to_str(snapshot)

azure-storage-file

Microsoft Azure Storage File Client Library for Python

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis