从磁盘读取/写入文件(Read/Write Files from Disk)#
使用磁盘文件读写节点从运行 n8n 的机器读取和写入文件。
🌐 Use the Read/Write Files from Disk node to read and write files from/to the machine where n8n is running.
此节点可以访问的路径取决于你的 n8n 部署。有关详细信息,请参阅 文件位置。
🌐 The paths this node can access depend on your n8n deployment. Refer to File locations for details.
操作(Operations)#
有关配置每个操作的节点的更多信息,请参阅以下章节。
🌐 Refer to the sections below for more information on configuring the node for each operation.
从磁盘读取文件(Read File(s) From Disk)#
使用以下参数配置此操作:
🌐 Configure this operation with these parameters:
- 文件选择器:输入你想要读取的文件路径。
- 要输入多个文件,请输入页面路径模式。你可以使用这些字符来定义路径模式:
*:匹配零次或多次任意字符,但不包括路径分隔符。**:匹配任意字符零次或多次,包括路径分隔符。?:匹配除路径分隔符之外的任意字符一次。[]:匹配括号内的任意字符。例如,[abc]将匹配字符a、b或c,而不会匹配其他字符。
- 要输入多个文件,请输入页面路径模式。你可以使用这些字符来定义路径模式:
有关这些字符及其预期行为的更多信息,请参阅 Picomatch 的基本 globbing 文档。
🌐 Refer to Picomatch's Basic globbing documentation for more information on these characters and their expected behavior.
从磁盘读取文件选项(Read File(s) From Disk options)#
你也可以使用这些选项来配置此操作:
🌐 You can also configure this operation with these Options:
- 文件扩展名:在节点输出中输入文件的扩展名。
- 文件名:在节点输出中输入文件的名称。
- MIME 类型:在节点输出中输入文件的 MIME 类型。有关文件扩展名及其 MIME 类型的列表,请参阅 常见 MIME 类型。
- 将输出文件放入字段:输入输出数据中用于存放文件的字段名称。
将文件写入磁盘(Write File to Disk)#
使用以下参数配置此操作:
🌐 Configure this operation with these parameters:
- 文件路径和名称:输入文件的存放位置、文件名称以及文件扩展名。
- 输入二进制字段:输入节点输入数据中将包含二进制文件的字段名称。
将文件写入磁盘选项(Write File to Disk options)#
你也可以使用这些选项来配置此操作:
🌐 You can also configure this operation with these Options:
此操作包括一个选项,即是将数据追加到现有文件(开启)还是创建新文件而不是追加到现有文件(关闭)。
🌐 This operation includes a single option, whether to Append data to an existing file instead of creating a new one (turned on) or to create a new file instead of appending to existing (turned off).
模板和示例(Templates and examples)#
文件位置(File locations)#
此节点可以读取和写入的路径取决于你的 n8n 部署。
🌐 The paths this node can read from and write to depend on your n8n deployment.
n8n 云(n8n Cloud)#
在 n8n Cloud 上,该节点只能访问 /home/node/ 目录下的路径。该目录外的路径(例如 /tmp/ 或 /data/)会因访问错误而失败。
🌐 On n8n Cloud, the node can only access paths under /home/node/. Paths outside this directory (for example, /tmp/ or /data/) fail with an access error.
云端的字段占位符
节点的 文件选择器 和 文件路径和名称 字段中的默认占位符(例如 /home/user/Pictures/**/*.png 和 /data/example.jpg)只是示例。在 Cloud 上,将它们替换为 /home/node/ 下的路径。
云文件系统是短暂的
此节点在云端写入的文件无法保证在工作流执行、工作节点重启或实例重新部署后依然存在。不要使用此节点存储需要保留的文件。
n8n 将 /home/node/.n8n/ 目录保留用于其内部状态。不要在此处写入自己的文件。
在云端进行持久文件处理,请使用云存储节点,例如 AWS S3、Google Drive 或 FTP。
自托管 n8n(Self-hosted n8n)#
在自托管的 n8n 上,默认情况下,该节点可以访问 n8n 进程能够访问的任何路径。要限制访问,请将 N8N_RESTRICT_FILE_ACCESS_TO 环境变量设置为一个或多个允许的目录(以分号分隔)。
🌐 On self-hosted n8n, by default the node can access any path the n8n process can reach. To restrict access, set the N8N_RESTRICT_FILE_ACCESS_TO environment variable to one or more allowed directories (semicolon-separated).
n8n 2.0 的默认更改
从 n8n 2.0 开始,N8N_RESTRICT_FILE_ACCESS_TO 默认值为 ~/.n8n-files。要在其他地方允许文件操作,请显式设置该变量。详情请参阅 n8n 2.0 重大更改。
如果你在 Docker 中运行 n8n,路径指的是 n8n 容器的文件系统,而不是 Docker 主机。要让主机目录对该节点可用,请将它们作为卷挂载到容器中。
🌐 If you run n8n in Docker, paths refer to the n8n container's filesystem, not the Docker host. To make host directories available to this node, mount them as volumes into the container.
n8n建议使用绝对文件路径以防止错误。
🌐 n8n recommends using absolute file paths to prevent errors.