Skip to content

外部存储(External storage)#

功能可用性

  • 提供给自托管企业版本
  • 如果你希望在云端企业版本中使用此功能,请联系 n8n

n8n 可以将工作流执行产生的二进制数据存储到外部。这一功能有助于避免依赖文件系统来存储大量二进制数据。

🌐 n8n can store binary data produced by workflow executions externally. This feature is useful to avoid relying on the filesystem for storing large amounts of binary data.

n8n 未来将引入对其他数据类型的外部存储支持。

🌐 n8n will introduce external storage for other data types in the future.

将 n8n 的二进制数据存储在 S3 中(Storing n8n's binary data in S3)#

n8n 支持将 AWS S3 用作工作流执行产生的二进制数据的外部存储。你也可以使用其他兼容 S3 的服务,如 Cloudflare R2 和 Backblaze B2,但 n8n 官方不支持这些服务。

🌐 n8n supports AWS S3 as an external store for binary data produced by workflow executions. You can use other S3-compatible services like Cloudflare R2 and Backblaze B2, but n8n doesn't officially support these.

企业级功能

您将需要一个企业许可证密钥来使用外部存储。如果您的许可证密钥过期且仍处于 S3 模式,实例将能够从 S3 存储桶读取数据,但无法写入数据。

设置(Setup)#

按照 AWS 文档 创建并配置一个存储桶。你可以使用以下策略,将 <bucket-name> 替换为你创建的存储桶名称:

🌐 Create and configure a bucket following the AWS documentation. You can use the following policy, replacing <bucket-name> with the name of the bucket you created:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
 "Version": "2012-10-17",
 "Statement": [
  {
   "Sid": "VisualEditor0",
   "Effect": "Allow",
   "Action": ["s3:*"],
   "Resource": ["arn:aws:s3:::<bucket-name>", "arn:aws:s3:::<bucket-name>/*"]
  }
 ]
}

设置存储桶级别的生命周期配置,以便 S3 自动删除旧的二进制数据。n8n 将二进制数据的清理工作委托给 S3,因此除非你想永久保留二进制数据,否则必须设置生命周期配置。

🌐 Set a bucket-level lifecycle configuration so that S3 automatically deletes old binary data. n8n delegates pruning of binary data to S3, so setting a lifecycle configuration is required unless you want to preserve binary data indefinitely.

创建桶完成后,你将获得主机、桶名称和区域,以及访问密钥 ID 和秘密访问密钥。你需要将它们设置在 n8n 的环境中:

🌐 Once you finish creating the bucket, you will have a host, bucket name and region, and an access key ID and secret access key. You need to set them in n8n's environment:

1
2
3
4
5
export N8N_EXTERNAL_STORAGE_S3_HOST=... # example: s3.us-east-1.amazonaws.com
export N8N_EXTERNAL_STORAGE_S3_BUCKET_NAME=...
export N8N_EXTERNAL_STORAGE_S3_BUCKET_REGION=...
export N8N_EXTERNAL_STORAGE_S3_ACCESS_KEY=...
export N8N_EXTERNAL_STORAGE_S3_ACCESS_SECRET=...

No region

If your provider doesn't require a region, you can set N8N_EXTERNAL_STORAGE_S3_BUCKET_REGION to 'auto'.

Tell n8n to store binary data in S3:

1
2
export N8N_AVAILABLE_BINARY_DATA_MODES=filesystem,s3
export N8N_DEFAULT_BINARY_DATA_MODE=s3

身份验证自动检测

要自动检测凭证以验证你的 S3 调用,请将 N8N_EXTERNAL_STORAGE_S3_AUTH_AUTO_DETECT 设置为 true。这将使用默认的凭证提供链

重启服务器以加载新配置。

🌐 Restart the server to load the new configuration.

用法(Usage)#

启用 S3 后,n8n 会将任何新的二进制数据写入和读取到 S3 存储桶。n8n 会以以下格式将二进制数据写入你的 S3 存储桶:

🌐 After you enable S3, n8n writes and reads any new binary data to and from the S3 bucket. n8n writes binary data to your S3 bucket in this format:

1
workflows/{workflowId}/executions/{executionId}/binary_data/{binaryFileId}

如果 filesystem 仍被列为 N8N_AVAILABLE_BINARY_DATA_MODES 的选项,n8n 将继续从文件系统中读取存储的旧二进制数据。

🌐 n8n continues to read older binary data stored in the filesystem from the filesystem, if filesystem remains listed as an option in N8N_AVAILABLE_BINARY_DATA_MODES.

如果你将二进制数据存储在 S3 中,之后切换到文件系统模式,只要 s3 仍然列在 N8N_AVAILABLE_BINARY_DATA_MODES 中且你的 S3 凭证有效,实例仍然可以读取存储在 S3 中的任何数据。

🌐 If you store binary data in S3 and later switch to filesystem mode, the instance continues to read any data stored in S3, as long as s3 remains listed in N8N_AVAILABLE_BINARY_DATA_MODES and your S3 credentials remain valid.

Binary data pruning

Binary data pruning operates on the active binary data mode. For example, if your instance stored data in S3, and you later switched to filesystem mode, n8n only prunes binary data in the filesystem. This may change in future.