Skip to content

ReadFile

根据文件路径读取文件内容,返回文件的文本内容。

业务属性

属性含义输入限定示例值
enable是否启用该控件,未启用时不编译选择值启用
name控件返回值命名常量Config
text与控件关联的文本常量getConfig
filePath文件绝对路径常量/流程变量#{body.filePath}

请使用文件的绝对路径,若使用相对路径可能会抛出找不到文件的异常

使用示例

假设我们在/usr/local/file路径下有一test.json文件。

文本的内容如下:

txt
This is a sample content from orapis
This is a sample content from orapis

输入常量

控件返回值命名为content,参数输入/usr/local/file/test.json

img_5.png

添加输出控件输出ReadFile控件的返回值content

img_6.png

data属性输入:

json
{
  "content": "#{content}"
}
{
  "content": "#{content}"
}

使用curl请求接口:

$ curl http://localhost:6636/api/readFile
$ curl http://localhost:6636/api/readFile

接口返回:

json
{
  "content": "This is a sample content from orapis"
}
{
  "content": "This is a sample content from orapis"
}

输入指定变量

参数输入#{body.filePath}

img_7.png

使用curl请求接口:

$ curl http://localhost:6636/api/readFile -d "{ \"filePath\": \"/usr/local/file/test.json\" }"
$ curl http://localhost:6636/api/readFile -d "{ \"filePath\": \"/usr/local/file/test.json\" }"

接口返回:

json
{
  "content": "This is a sample content from orapis"
}
{
  "content": "This is a sample content from orapis"
}