html - 通过 Databricks 上传到 Azure Blob 存储时设置内容类型
问题描述
我正在使用databricks
平台上传静态站点,专门使用以下命令将html
内容推送到某个位置。
dbutils.fs.put("/mnt/$web/index.html", html, overwrite=True)
这是有效的,但 HTML 文件正在下载而不是显示。这是因为内容类型错误: Content-Type: application/octet-stream
。
有没有办法设置这个使用databricks
?
解决方案
最后,这段代码对我有用。首先,我从 databricks 范围获取连接字符串
dbutils.secrets.get(scope = "generic-scope", key = "website-key")
如果您没有,请在存储帐户的容器访问密钥中查找它
from azure.storage.blob import BlobServiceClient, ContentSettings
connect_str="connectionString"
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
# Instantiate a ContainerClient
container_client = blob_service_client.get_container_client("$web")
# List files in blob folder
blobs_list = container_client.list_blobs()
for blob in blobs_list:
print(blob.content_settings.content_type) # application/octet-stream
blob.set_http_headers(
content_settings=ContentSettings(
content_type="text/html; charset=utf-8"
)
)
推荐阅读
- asp.net - Asp.Net Web API - 如何在不使用 mutlipart 的情况下接受 REST 端点中的文件?
- django - 如何在自定义用户模型中使用 django-guardian
- java - 检查文件的成功副本
- json - VueJS API 结果按等级 asc 排序
- mongodb - 嵌套 localField 时的 $lookup
- javascript - 等待 Promise 返回的第一个 true 的干净方式
- excel - Excel VBA需要帮助处理文件夹中的多个文件
- swift - Swift 问题:设置名为 map 的属性
- tableau-api - 自定义 SQL 查询中的参数在计算视图布局中永久存在
- javascript - 如何将 .then 的解析值分配给变量?