Help Center> FunctionGraph> FAQ> General FAQs> How Does a Function Read or Write Files?

How Does a Function Read or Write Files?

Background

A function can read files in the code directory. The working directory of a function is the upper-level directory of the handler file. To read the test.conf file in the same directory level as the handler file, use the relative path code/test.conf or an absolute path (value of the RUNTIME_CODE_ROOT environment variable). To write a file (for example, to create or download a file), go to the /tmp directory or use the file system mounting function provided by FunctionGraph.

Typical Scenarios

  • Download files stored in Object Storage Service (OBS) to the /tmp directory for processing.
  • To store function execution data in OBS, create a file in the /tmp directory, write the data into the file, and then upload the file to OBS.