You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Blob存储中IngestionTimestamp文件夹冒号转义为%3A的解决请求

解决Azure Blob Storage中文件夹名称冒号被编码为%3A的问题

问题核心

你构造的ISO 8601格式时间戳在本地显示正常,但上传到Azure Blob Storage后,冒号被自动编码为%3A。这是因为Azure存储SDK默认会对URL保留字符进行编码,但实际上Blob存储支持路径中包含冒号,只需调整代码逻辑即可避免自动编码。

修正方案

直接构造包含冒号的完整时间戳字符串,通过SDK标准方法创建虚拟文件夹(无需使用unquote,该操作对未编码的字符串无效):

完整代码示例

from datetime import datetime, timezone
from azure.storage.blob import BlobServiceClient

# 1. 构造符合要求的IngestionTimestamp路径
current_timestamp = datetime.now(timezone.utc)
ingestion_folder_name = f"IngestionTimestamp={current_timestamp.strftime('%Y-%m-%dT%H:%M:%S+00:00')}"

# 2. 连接Azure Blob存储(替换为你的连接字符串和容器名)
connection_string = "你的Azure存储连接字符串"
container_name = "目标容器名称"

blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client(container_name)

# 3. 创建虚拟文件夹(通过上传空Blob实现,路径以/结尾)
folder_blob_path = f"{ingestion_folder_name}/"
container_client.upload_blob(name=folder_blob_path, data=b"", overwrite=True)

关键说明

  1. 移除多余的unquote操作:你原本构造的current_timestamp_str + '+00:00'已经是带冒号的合法字符串,unquote对未经过URL编码的字符串没有作用,完全没必要添加。
  2. 利用SDK标准方法:Azure Blob存储的虚拟文件夹本质是路径以/结尾的空Blob,通过upload_blob方法直接指定带冒号的路径,SDK会正确处理路径字符,不会将冒号编码为%3A。
  3. 时间戳格式直接生成:通过strftime('%Y-%m-%dT%H:%M:%S+00:00')直接生成包含时区的完整ISO 8601字符串,无需手动拼接时区部分。

内容的提问来源于stack exchange,提问作者Kramer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 13:28:11