当前位置: 首页>>代码示例>>Python>>正文


Python blob.ContentSettings方法代码示例

本文整理汇总了Python中azure.storage.blob.ContentSettings方法的典型用法代码示例。如果您正苦于以下问题:Python blob.ContentSettings方法的具体用法?Python blob.ContentSettings怎么用?Python blob.ContentSettings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.storage.blob的用法示例。


在下文中一共展示了blob.ContentSettings方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _save

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def _save(self, name, content):
        cleaned_name = clean_name(name)
        name = self._get_valid_path(name)
        guessed_type, content_encoding = mimetypes.guess_type(name)
        content_type = (
            _content_type(content) or
            guessed_type or
            self.default_content_type)

        # Unwrap django file (wrapped by parent's save call)
        if isinstance(content, File):
            content = content.file

        content.seek(0)
        self.service.create_blob_from_stream(
            container_name=self.azure_container,
            blob_name=name,
            stream=content,
            content_settings=ContentSettings(
                content_type=content_type,
                content_encoding=content_encoding,
                cache_control=self.cache_control),
            max_connections=self.upload_max_conn,
            timeout=self.timeout)
        return cleaned_name 
开发者ID:jschneier,项目名称:django-storages,代码行数:27,代码来源:azure_storage.py

示例2: store_file_object

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def store_file_object(self, key, fd, *, cache_control=None, metadata=None, mimetype=None, upload_progress_fn=None):
        if cache_control is not None:
            raise NotImplementedError("AzureTransfer: cache_control support not implemented")
        key = self.format_key_for_backend(key, remove_slash_prefix=True)
        content_settings = None
        if mimetype:
            content_settings = ContentSettings(content_type=mimetype)

        def progress_callback(bytes_sent, _):
            if upload_progress_fn:
                upload_progress_fn(bytes_sent)

        # Azure _BlobChunkUploader calls `tell()` on the stream even though it doesn't use the result.
        # We expect the input stream not to support `tell()` so use dummy implementation for it
        original_tell = getattr(fd, "tell", None)
        fd.tell = lambda: None
        try:
            self.conn.create_blob_from_stream(self.container_name, key, fd, content_settings=content_settings,
                                              metadata=self.sanitize_metadata(metadata, replace_hyphen_with="_"),
                                              progress_callback=progress_callback)
        finally:
            if original_tell:
                fd.tell = original_tell
            else:
                delattr(fd, "tell") 
开发者ID:aiven,项目名称:pghoard,代码行数:27,代码来源:azure.py

示例3: _upload_index_file

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def _upload_index_file(service, blob_name, title, links):
    print('Uploading index file {}'.format(blob_name))
    service.create_blob_from_text(
        container_name=BLOB_CONTAINER_NAME,
        blob_name=blob_name,
        text="<html><head><title>{0}</title></head><body><h1>{0}</h1>{1}</body></html>"
        .format(title, '\n'.join(
            ['<a href="{0}">{0}</a><br/>'.format(link) for link in links])),
        content_settings=ContentSettings(
            content_type='text/html',
            content_disposition=None,
            content_encoding=None,
            content_language=None,
            content_md5=None,
            cache_control=None
        )
    ) 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:19,代码来源:release.py

示例4: put_contents

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def put_contents(self, contents, dest, sync=False):
        dest_path = self.prefixed_path(dest)
        logger.debug('Writing content to azure: {0}'.format(dest_path))
        content_settings = ContentSettings(content_type=guess_content_type(dest))
        self.container_client.upload_blob(name=dest_path, data=contents.encode('utf-8'),
                                          overwrite=True, content_settings=content_settings) 
开发者ID:helpshift,项目名称:pypiprivate,代码行数:8,代码来源:azure.py

示例5: put_file

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def put_file(self, src, dest, sync=False):
        dest_path = self.prefixed_path(dest)
        logger.debug('Writing content to azure: {0}'.format(dest_path))
        content_settings = ContentSettings(content_type=guess_content_type(dest))
        with open(src, "rb") as data:
            self.container_client.upload_blob(name=dest_path, data=data,
                                              overwrite=True, content_settings=content_settings) 
开发者ID:helpshift,项目名称:pypiprivate,代码行数:9,代码来源:azure.py

示例6: stream_write

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def stream_write(self, path, fp, content_type=None, content_encoding=None):
        blob_name = self._blob_name_from_path(path)
        content_settings = ContentSettings(
            content_type=content_type, content_encoding=content_encoding,
        )

        try:
            self._blob_service.create_blob_from_stream(
                self._azure_container, blob_name, fp, content_settings=content_settings
            )
        except AzureException as ae:
            logger.exception("Exception when trying to stream_write path %s", path)
            raise IOError("Exception when trying to stream_write path", ae) 
开发者ID:quay,项目名称:quay,代码行数:15,代码来源:azurestorage.py

示例7: upload_object

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def upload_object(self, file_path, container, object_name, extra=None, **kwargs):
        from azure.common import AzureHttpError

        blob_name = self._blob_name_from_object_path(object_name, container.name)
        stream = None
        try:
            from azure.storage.blob import ContentSettings
            from mimetypes import guess_type
            container.blob_service.MAX_SINGLE_PUT_SIZE = 16 * 1024 * 1024
            container.blob_service.socket_timeout = (300, 2000)
            container.blob_service.create_blob_from_path(
                container.name,
                blob_name,
                file_path,
                # timeout=300,
                max_connections=2,
                content_settings=ContentSettings(content_type=guess_type(file_path))
            )
            return True
        except AzureHttpError as ex:
            log.error('Failed uploading (Azure error): %s' % ex)
        except Exception as ex:
            log.error('Failed uploading: %s' % ex)
        finally:
            if stream:
                stream.close() 
开发者ID:allegroai,项目名称:trains,代码行数:28,代码来源:helper.py

示例8: store_file_from_memory

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def store_file_from_memory(self, key, memstring, metadata=None, cache_control=None, mimetype=None):
        if cache_control is not None:
            raise NotImplementedError("AzureTransfer: cache_control support not implemented")
        key = self.format_key_for_backend(key, remove_slash_prefix=True)
        content_settings = None
        if mimetype:
            content_settings = ContentSettings(content_type=mimetype)
        self.conn.create_blob_from_bytes(self.container_name, key,
                                         bytes(memstring),  # azure would work with memoryview, but validates it's bytes
                                         content_settings=content_settings,
                                         metadata=self.sanitize_metadata(metadata, replace_hyphen_with="_")) 
开发者ID:aiven,项目名称:pghoard,代码行数:13,代码来源:azure.py

示例9: store_file_from_disk

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def store_file_from_disk(self, key, filepath, metadata=None, multipart=None, cache_control=None, mimetype=None):
        if cache_control is not None:
            raise NotImplementedError("AzureTransfer: cache_control support not implemented")
        key = self.format_key_for_backend(key, remove_slash_prefix=True)
        content_settings = None
        if mimetype:
            content_settings = ContentSettings(content_type=mimetype)
        self.conn.create_blob_from_path(self.container_name, key, filepath, content_settings=content_settings,
                                        metadata=self.sanitize_metadata(metadata, replace_hyphen_with="_")) 
开发者ID:aiven,项目名称:pghoard,代码行数:11,代码来源:azure.py

示例10: set_contents_from_filename

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def set_contents_from_filename(self, filename):
        if hasattr(self, 'content_type') and self.content_type is not None:
            mimetype = self.content_type
        else:
            mimetype, encoding = mimetypes.guess_type(filename)
        if mimetype is not None:
            self.azure_object.conn.create_blob_from_path(self.azure_object.container, self.name, filename, content_settings=ContentSettings(content_type=mimetype))
        else:
            self.azure_object.conn.create_blob_from_path(self.azure_object.container, self.name, filename)
        self.get_properties()
        secs = (self.last_modified - epoch).total_seconds()
        os.utime(filename, (secs, secs)) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:14,代码来源:microsoft.py

示例11: complete_chunked_upload

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def complete_chunked_upload(self, uuid, final_path, storage_metadata):
        """
        Complete the chunked upload and store the final results in the path indicated.

        Returns nothing.
        """
        # Commit the blob's blocks.
        upload_blob_path = self._upload_blob_path_from_uuid(uuid)
        block_list = [BlobBlock(block_id) for block_id in storage_metadata[_BLOCKS_KEY]]

        try:
            self._blob_service.put_block_list(self._azure_container, upload_blob_path, block_list)
        except AzureException:
            logger.exception(
                "Exception when trying to put block list for path %s from upload %s",
                final_path,
                uuid,
            )
            raise IOError("Exception when trying to put block list")

        # Set the content type on the blob if applicable.
        if storage_metadata[_CONTENT_TYPE_KEY] is not None:
            content_settings = ContentSettings(content_type=storage_metadata[_CONTENT_TYPE_KEY])
            try:
                self._blob_service.set_blob_properties(
                    self._azure_container, upload_blob_path, content_settings=content_settings
                )
            except AzureException:
                logger.exception(
                    "Exception when trying to set blob properties for path %s", final_path
                )
                raise IOError("Exception when trying to set blob properties")

        # Copy the blob to its final location.
        upload_blob_name = self._upload_blob_name_from_uuid(uuid)
        copy_source_url = self.get_direct_download_url(upload_blob_name, expires_in=300)

        try:
            blob_name = self._blob_name_from_path(final_path)
            copy_prop = self._blob_service.copy_blob(
                self._azure_container, blob_name, copy_source_url
            )
        except AzureException:
            logger.exception(
                "Exception when trying to set copy uploaded blob %s to path %s", uuid, final_path
            )
            raise IOError("Exception when trying to copy uploaded blob")

        self._await_copy(self._azure_container, blob_name, copy_prop)

        # Delete the original blob.
        logger.debug("Deleting chunked upload %s at path %s", uuid, upload_blob_path)
        try:
            self._blob_service.delete_blob(self._azure_container, upload_blob_path)
        except AzureException:
            logger.exception("Exception when trying to set delete uploaded blob %s", uuid)
            raise IOError("Exception when trying to delete uploaded blob") 
开发者ID:quay,项目名称:quay,代码行数:59,代码来源:azurestorage.py

示例12: upload_icon

# 需要导入模块: from azure.storage import blob [as 别名]
# 或者: from azure.storage.blob import ContentSettings [as 别名]
def upload_icon(sas_url, file_path):
    # Break the SAS URL
    (scheme, netloc, path, params, query, fragment) = urlparse(sas_url)
    # Account is the first part of the netlocation upto the dot
    account_name = netloc[0:netloc.index('.')]

    # The assumption here is that the blob URL will be in the
    # form accountname.blob.core.windows.net or
    # accountname.blob.core.usgovcloudapi.net.
    # Chopping off accountname.blob. to obtain the
    # endpoint suffix.
    endpoint_suffix = netloc.replace(account_name+'.blob.', '')

    # Container name is the path
    container_name = path.strip('/')

    # Create a block blob service
    blockblob_service = BlockBlobService(
        account_name=account_name,
        sas_token=query,
        endpoint_suffix=endpoint_suffix)

    # Get the file name of the icon
    file_name = os.path.basename(file_path)
    # Determine the content type and encoding for the file
    (content_type, content_encoding) = mimetypes.guess_type(file_name)
    content_settings = ContentSettings(
        content_type=content_type,
        content_encoding=content_encoding)

    # Upload the icon
    blockblob_service.create_blob_from_path(
        container_name=container_name,
        blob_name=file_name,
        file_path=file_path,
        content_settings=content_settings)

    # Append the icon name to the path to generate the download link
    path = path + '/' + file_name
    urlparts = (scheme, netloc, path, params, query, fragment)
    sas_download_url = urlunparse(urlparts)

    return sas_download_url 
开发者ID:microsoft,项目名称:PowerPlatformConnectors,代码行数:45,代码来源:iconuploader.py


注:本文中的azure.storage.blob.ContentSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。