# Azure - Blob Storage

> 在 Azure Blob Storage 容器中上传、下载、列出和删除 blob（文件）。

Source: https://docs.sommatic.ai/zh/nodes/integrations.microsoft.azure.blob/

- 标识: `integrations.microsoft.azure.blob`
- 类别: 集成
- 版本: 1.0.0
- 状态: 可用
- 执行方式: async

在 Azure Blob Storage 容器中上传、下载、列出和删除 blob（文件）。

连接你的 Azure 存储账户，自动化文件操作：存储工作流输出、获取待处理的文档、列出容器内容，以及管理 blob 生命周期。

**操作：**
- **Upload：** 将内容上传到指定容器中的 blob。
- **Download：** 按名称下载 blob 内容。
- **List：** 列出容器中的所有 blob。
- **Delete：** 按名称删除指定 blob。

## 配置

- `connection_id` (string, 必填): Azure Blob Storage 的凭据。接受 `connection-string`（DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;）或 `basic-auth`（accountName + accountKey）类型的凭据。
- `container` (string, 必填, 支持表达式): 要操作的 blob 容器名称。
- `operation` (string, 必填): 要执行的存储操作。 默认值: `download`. 可选值: `download`, `upload`, `list`, `delete`.
- `blobName` (string, 可选, 支持表达式): blob 的路径/名称（例如“reports/2024/summary.pdf”）。 显示条件: operation = `download` | `upload` | `delete`.
- `content` (string, 可选, 支持表达式): 作为 blob 正文上传的内容（字符串或 base64）。 显示条件: operation = `upload`.

## 输出端口

- `out` (默认): 操作结果
- `error`: 存储操作失败

## 输入契约

- `connection_id` (string, 必填)
- `container` (string, 必填)
- `operation` (string, 必填)
- `blobName` (string, 可选)
- `content` (string, 可选)

## 输出契约

- `result` (object, 可选): Blob 操作结果

## 在表达式中

后续节点可通过 `$("Azure - Blob Storage").item.json.<路径>` 读取此节点输出中的内容（请把 `Azure - Blob Storage` 换成你的节点标签）。**Editor** 标记工作流编辑器在 Previous Nodes 中提示的路径（输出契约）；**Worker** 标记 worker 实际通过 `out` 返回的路径，依据“端口”一节所示的输出。

- `$("Azure - Blob Storage").item.json.result` (object) = `{…}`: Blob 操作结果
- `$("Azure - Blob Storage").item.json.result.url` (string) = `"https://myaccount.blob.core.windows.net/docu…"` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.blob_name` (string) = `"inbound/ord_123.json"` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.container` (string) = `"documents"` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.etag` (string) = `"\"0x8DD0E5C2A1B3F00\""` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.last_modified` (string) = `"2026-11-26T14:03:11.000Z"` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.request_id` (string) = `"5f1c7a2e-001e-0045-2b3c-3e0f8b000000"` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.version_id` (null) = `null` (编辑器不提示)
- `$("Azure - Blob Storage").item.json.result.content_md5` (null) = `null` (编辑器不提示)


## 工作原理

对容器执行一次 Azure Blob Storage 操作（download、upload、list 或 delete），并将结果放在 `result` 中返回。存储的瞬时故障会以有上限的指数退避方式重试。

1. 解析节点配置中的表达式。若 `connection_id`、`operation`、`container`、`blobName` 或 `content` 为空，worker 会从输入项（`$json`）读取同名字段。`operation` 默认为 `download`。
2. 按以下来源构建存储客户端：直接写在 `connection_id` 中的连接字符串（包含 `DefaultEndpointsProtocol=`、`AccountName=` 或 `UseDevelopmentStorage=true`）；`connection-string` 类型凭据；或包含 `accountName` 与 `accountKey`（或 `password`）的 `basic-auth` / `object` 凭据，此时访问 `https://<accountName>.blob.core.windows.net`。
3. 执行操作：`download` 以字符串读取整个 blob；`upload` 将 `content` 写入 `blobName`（覆盖已有内容），返回不含查询字符串的 URL 以及 `etag`、`last_modified`、`request_id`、`version_id`、`content_md5`；`list` 返回容器内所有 blob 名称；`delete` 删除 `blobName` 并返回 SDK 响应。
4. 仅对存储调用本身重试（不包括凭据解析），触发条件为网络错误（ETIMEDOUT、ECONNRESET、ECONNREFUSED、ENOTFOUND 等）、HTTP 429、HTTP 5xx 和超时。认证错误及其他 4xx 不重试。
5. 成功时经 `out` 返回 `{ result }`。任何失败都以 `{ error }` 经 `error` 返回；节点不会抛出异常。

## 在工作流中

### 节点

```json
{
  "node_id": "node-store-order",
  "label": "Store order JSON",
  "operator_slug": "integrations.microsoft.azure.blob",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "container": "documents",
    "operation": "upload",
    "blobName": "inbound/{{ $json.order_id }}.json",
    "content": "{{ $json.serialized_order }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "result": {
      "url": "https://myaccount.blob.core.windows.net/documents/inbound/ord_123.json",
      "blob_name": "inbound/ord_123.json",
      "container": "documents",
      "etag": "\"0x8DD0E5C2A1B3F00\"",
      "last_modified": "2026-11-26T14:03:11.000Z",
      "request_id": "5f1c7a2e-001e-0045-2b3c-3e0f8b000000",
      "version_id": null,
      "content_md5": null
    }
  },
  "port": "out"
}
```

## 输出端口 (代码中的行为)

### `out`

操作成功。`result` 为字符串（`download`）、包含 blob URL 与元数据的对象（`upload`）、blob 名称数组（`list`）或 SDK 删除响应（`delete`）。

```json
{
  "result": {
    "url": "https://myaccount.blob.core.windows.net/documents/inbound/ord_123.json",
    "blob_name": "inbound/ord_123.json",
    "container": "documents",
    "etag": "\"0x8DD0E5C2A1B3F00\"",
    "last_modified": "2026-11-26T14:03:11.000Z",
    "request_id": "5f1c7a2e-001e-0045-2b3c-3e0f8b000000",
    "version_id": null,
    "content_md5": null
  }
}
```

### `error`

校验、凭据解析失败，或存储调用在允许的尝试次数后仍失败。

```json
{
  "error": "blobName required for upload"
}
```

## 代码中的行为

- `execution`: 未在本节点的 schema 中声明，但会被读取：`retryOnFail: false` 表示只尝试一次；否则使用 `maxTries`（默认 3），并以 `waitBetweenTries` 作为基础退避时间。不做任何设置时，存储调用最多尝试 3 次。
- `http_retry_max_attempts`: 未声明。设置后覆盖尝试次数，始终限制在 1–5 之间。
- `http_retry_backoff_ms`: 未声明。基础等待时间（毫秒，默认 1000），每次尝试翻倍，并附加最多 250 毫秒的随机抖动。
- `http_retry_max_wait_ms`: 未声明。每次等待的上限（默认 20000，最大不超过 30000）。
- `content`: 以字符串上传，长度取 `content.length`，按字符而非字节计数。上传非 ASCII 文本前请先进行 base64 编码。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `connection_id is required` | `error` | 配置和输入项中都没有凭据。`container is required` 同理。 |
| `blobName required for <operation>` | `error` | `upload`、`download` 和 `delete` 需要 `blobName`。 |
| `Unknown operation: <operation>` | `error` | `operation` 不是 download、upload、list 或 delete。 |
| `Credential <connection_id> has unsupported type '<type>' for integrations.microsoft.azure.blob. Use 'connection-string' or 'basic-auth'.` | `error` | 该凭据类型无法映射到存储账户。请使用 `connection-string` 或 `basic-auth` 凭据。 |
| `Credential <connection_id> (type '<type>') missing accountName / accountKey` | `error` | 结构化凭据缺少账户名或账户密钥。 |
| `Cannot read properties of undefined (reading 'length')` | `error` | 执行 `upload` 时未提供 `content`。 |
| `The specified blob does not exist.<…>` | `error` | 对不存在的 blob 执行 `download` 或 `delete` 时的 Azure 错误；其他 Azure 错误也按原样传递。 |

## 说明与限制

- 所有操作都是幂等的，因此重试是安全的：upload 覆盖同名 blob，download 与 list 是读操作，重复 delete 不会造成影响。
- Azure SDK 自带的重试已关闭，worker 的重试策略是唯一的重试层。
- `download` 会将 blob 按文本解码，二进制内容无法完整返回。`list` 不支持前缀过滤，会读取容器的全部分页。


## 契约（JSON Schema）

### All (`*.definition.js`)

```json
{
  "slug": "integrations.microsoft.azure.blob",
  "name": "Azure - Blob Storage",
  "category": "integrations",
  "group": [
    {
      "key": "microsoft",
      "name": "Microsoft",
      "icon_url": "/icons/integrations/microsoft/microsoft.svg"
    },
    {
      "key": "azure",
      "name": "Azure",
      "icon_url": "/icons/integrations/microsoft/azure.svg"
    }
  ],
  "icon_url": "/icons/integrations/microsoft/azure-blob.svg",
  "version": "1.0.0",
  "description": "Upload, download, list, and delete blobs (files) on Azure Blob Storage containers.\n\n  Connect your Azure Storage Account and automate file operations — store workflow outputs, retrieve documents for processing, list container contents, and manage blob lifecycle.\n\n  **Operations:**\n  - **Upload:** Upload content to a blob in the specified container.\n  - **Download:** Download a blob's content by name.\n  - **List:** List all blobs in a container.\n  - **Delete:** Delete a specific blob by name.",
  "capabilities": [
    "storage",
    "azure",
    "blob",
    "files",
    "cloud"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Azure Storage Credential",
        "description": "Credential for Azure Blob Storage. Accepts credentials of type `connection-string` (DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;) or `basic-auth` (accountName + accountKey).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "connection-string",
            "basic-auth"
          ],
          "types": [
            "azure.blob",
            "azure"
          ]
        }
      },
      "container": {
        "type": "string",
        "title": "Container",
        "description": "Name of the blob container to operate on.",
        "format": "expression"
      },
      "operation": {
        "type": "string",
        "title": "Operation",
        "enum": [
          "download",
          "upload",
          "list",
          "delete"
        ],
        "default": "download",
        "description": "The storage operation to perform."
      },
      "blobName": {
        "type": "string",
        "title": "Blob Name",
        "description": "Path/name of the blob (e.g., \"reports/2024/summary.pdf\").",
        "format": "expression",
        "displayOptions": {
          "show": {
            "operation": [
              "download",
              "upload",
              "delete"
            ]
          }
        }
      },
      "content": {
        "type": "string",
        "title": "Content",
        "description": "Content to upload as blob body (string or base64).",
        "format": "expression",
        "displayOptions": {
          "show": {
            "operation": [
              "upload"
            ]
          }
        }
      }
    },
    "required": [
      "connection_id",
      "container",
      "operation"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "container": {
        "type": "string"
      },
      "operation": {
        "type": "string"
      },
      "blobName": {
        "type": "string"
      },
      "content": {
        "type": "string"
      }
    },
    "required": [
      "connection_id",
      "container",
      "operation"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "Blob operation result"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "Operation result",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Storage operation failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "cloud-io"
  ],
  "tags": [
    "storage",
    "cloud",
    "azure"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://sommatic.ai",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Azure Storage Credential",
      "description": "Credential for Azure Blob Storage. Accepts credentials of type `connection-string` (DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;) or `basic-auth` (accountName + accountKey).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "connection-string",
          "basic-auth"
        ],
        "types": [
          "azure.blob",
          "azure"
        ]
      }
    },
    "container": {
      "type": "string",
      "title": "Container",
      "description": "Name of the blob container to operate on.",
      "format": "expression"
    },
    "operation": {
      "type": "string",
      "title": "Operation",
      "enum": [
        "download",
        "upload",
        "list",
        "delete"
      ],
      "default": "download",
      "description": "The storage operation to perform."
    },
    "blobName": {
      "type": "string",
      "title": "Blob Name",
      "description": "Path/name of the blob (e.g., \"reports/2024/summary.pdf\").",
      "format": "expression",
      "displayOptions": {
        "show": {
          "operation": [
            "download",
            "upload",
            "delete"
          ]
        }
      }
    },
    "content": {
      "type": "string",
      "title": "Content",
      "description": "Content to upload as blob body (string or base64).",
      "format": "expression",
      "displayOptions": {
        "show": {
          "operation": [
            "upload"
          ]
        }
      }
    }
  },
  "required": [
    "connection_id",
    "container",
    "operation"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "container": {
      "type": "string"
    },
    "operation": {
      "type": "string"
    },
    "blobName": {
      "type": "string"
    },
    "content": {
      "type": "string"
    }
  },
  "required": [
    "connection_id",
    "container",
    "operation"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": "object",
      "description": "Blob operation result"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Result",
    "description": "Operation result",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Storage operation failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
