如何批量上传文件至Azure ADLS Gen2?替代Blob upload-batch的简便方法
批量上传文件到ADLS Gen2的简便方法
你完全不需要编写循环,现有的Azure CLI命令就支持ADLS Gen2的批量上传,有两种方式可选:
方式1:继续使用az storage blob upload-batch(兼容ADLS Gen2)
ADLS Gen2是构建在Azure Blob存储之上的,因此原本用于Blob存储的upload-batch命令完全适配ADLS Gen2账户,只需确保你的存储账户已启用分层命名空间(ADLS Gen2的核心特性)。
示例命令(和你原来的用法几乎一致,可直接复用):
az storage blob upload-batch \ --destination "adls-container-name" \ --account-name "your-adls-account-name" \ --source "./files"
如果需要上传到容器下的指定目录,直接将路径追加到--destination参数中即可:
az storage blob upload-batch \ --destination "adls-container-name/subfolder/sub-subfolder" \ --account-name "your-adls-account-name" \ --source "./files"
方式2:使用ADLS Gen2专属命令az storage fs file upload-batch
Azure CLI提供了针对ADLS Gen2文件系统的专属批量上传命令,语义上更贴合ADLS的目录结构(自动创建不存在的目录),用法和blob upload-batch完全一致:
示例命令:
az storage fs file upload-batch \ --destination "adls-filesystem-name/subfolder-path" \ --account-name "your-adls-account-name" \ --source "./files"
注意事项
- 确保执行命令的身份(如流水线服务主体)拥有Storage Blob Data Contributor或对应的RBAC权限,否则会出现权限不足的错误。
- 两种命令都支持批量处理整个目录下的文件,无需手动遍历。
内容的提问来源于stack exchange,提问作者Tim
相关产品推荐
相关产品推荐

