$.files
The $.files
helper is the main module to interact with the Project’s File Store. It can instatiate new files, open files from descriptors and list the contents of the File Store.
$.files.open(path)
Sync. Opens a file from the relative path
. If the file doesn’t exist, a new empty file is created.
$.files.openDescriptor(fileDescriptor)
Sync. Creates a new File
from the JSON friendly description of a file. Useful for recreating a File
from a step export.
For example, export a File
as a step export which will render the File
as JSON:
File
instance from the step export friendly description:
$.files.dir(?path)
Sync. Lists the files & directories at the given path
. By default it will list the files at the root directory.
Here’s an example of how to iterate over the files in the root directory and open them as File
instances:
$.files.dir()
will contain the following properties:
isDirectory()
-true
if this instance is a directory.isFile()
-true
if this instance is a file.path
- The path to the file.size
- The size of the file in bytes.modifiedAt
- The last modified at timestamp.
File
This class describes an instance of a single file within a File Store.
When using $.files.open
or $.files.openDescriptor
, you’ll create a new instance of a File
with helper methods that give you more flexibility to perform programatic actions with the file.
File.toUrl()
Async. The pre-signed GET URL to retrieve the file.
Pre-signed GET URLs are short lived.The
File.toUrl()
will expire after 30 minutes.File.toFile(path)
Async. Downloads the file to the local path in the current workflow. If the file doesn’t exist, a new one will be created at the path specified.
Only
/tmp
is writable in workflow environmentsOnly the /tmp
directory is writable in your workflow’s exection environment. So you must download your file to the /tmp
directory.File.toBuffer()
Async. Downloads the file as a Buffer to create readable or writeable streams.
File.fromFile(localFilePath, ?contentType)
Async. Uploads a file from the file at the /tmp
local path. For example, if localFilePath
is given /tmp/recording.mp3
, it will upload that file to the current File Store File instance.
File.fromUrl(url)
Async. Accepts a url
to read from.
File.createWriteStream(?contentType, ?contentLength)
Async. Creates a write stream to populate the file with.
Pass the content length if possibleThe
contentLength
argument is optional, however we do recommend passing it. Otherwise the entire file will need to be written to the local /tmp
before it can be uploaded to the File store.File.fromReadableStream(?contentType, ?contentLength)
Async. Populates a file’s contents from the ReadableStream
.
Pass the content length if possibleThe
contentLength
argument is optional, however we do recommend passing it. Otherwise the entire file will need to be written to the local /tmp
before it can be uploaded to the File store.File.delete()
Async. Deletes the Project File.
Deleting files is irreversibleIt’s not possible to restore deleted files. Please take care when deleting files.