如何在Azure Blob存储中自动设置Brotli编码?

问题描述 投票:0回答:1

使用Azure Portal blob存储通过浏览器上传文件,如何让系统自动检测到使用Brotli压缩的文件并将'br'设置为编码类型?

例如,如果我使用浏览器中的 Azure 门户文件上传功能上传 .js 文件,该文件的内容类型会自动设置为“application/x-javascript”。

如果我上传扩展名为 .br 的文件,Azure 存储是否可以检测到它是“brotli”压缩文件,从而自动将该文件的内容编码设置为“br”?现在我必须对每个文件手动执行此操作。

azure-blob-storage file-type brotli
1个回答
0
投票

如果上传扩展名为 .br 的文件,Azure 存储是否可以将其检测为“brotli”压缩文件并自动将该文件的内容编码设置为“br”?

Azure 不会自动添加您的

content-encoding
。如果您需要上传内容编码设置为
br
的blob,您可以使用以下Python代码,该代码将上传.br扩展文件并设置内容编码。

代码:

import brotli
from azure.storage.blob import BlobServiceClient, ContentSettings

blob_service_client = BlobServiceClient.from_connection_string("xxxx")
container_client = blob_service_client.get_container_client("block-image")
blob_client = container_client.get_blob_client("sample.br")

with open(r"path of file") as f:
    data = f.read()A
    compressed_data = brotli.compress(data)

# Upload the compressed file to Azure Blob Storage
blob_client.upload_blob(compressed_data, blob_type="BlockBlob", content_settings=ContentSettings(content_encoding="br"))

执行上述代码并通过设置内容编码将文件上传到Azure Blob存储。

输出: enter image description here

参考:

© www.soinside.com 2019 - 2024. All rights reserved.