DocsReferenceAPI reference

Storage files

Files in the device storage (littlefs): apps /apps/<id>/, app data /data/<id>/, fonts /fonts/, device web app /www/. Files are read and written whole, ≤ 2 MB

GET /v1/fs/list#

List a storage folder (up to 256 entries)

Signature required Kernel only

Lists the files and subfolders one level deep, with the storage total and used bytes

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringpattern ^/length 1–96; ≤ 96 bytesFolder; the root / when omitted

Reply#

Folder listing

Folder listing for storage and the microSD card (same format)

FieldTypeRequiredValuesRangeDescription
okbooleanYestrueAlways true
pathstringYesThe folder listed
entriesobject[]Yes≤ 256 itemsEntries, up to 256, in no particular order
namestringYesName (without the path)
dirbooleanYesWhether it is a folder
sizeinteger≥ 0File size in bytes; absent for folders
truncatedbooleantrue when there are more than 256 entries (only 256 returned)
totalintegerYes≥ 0Total bytes of the storage or card
usedintegerYes≥ 0Used bytes

Error codes#

StatusCodeDescription
400bad_pathpath is missing or invalid (see path)
404not_foundNo such folder
400not_dirpath is a file. Read files with GET /v1/fs
503no_storageStorage is not mounted. Restart the device; if it persists, check stick logs
500io_errorStorage read/write error. Retry; if it persists, check stick logs

For errors any endpoint can return, see Common errors.

GET /v1/fs#

Read a storage file (whole file)

Signature required Kernel only

The reply is the file's raw bytes. Host: stick fs get

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringYespattern ^/length 1–96; ≤ 96 bytesFile

Reply#

File content

The reply is binary.

application/octet-stream

Error codes#

StatusCodeDescription
400bad_pathpath is missing or invalid (see path)
404not_foundNo such file
400is_dirpath is a folder. List it with GET /v1/fs/list
503no_storageStorage is not mounted. Restart the device; if it persists, check stick logs
500io_errorStorage read/write error. Retry; if it persists, check stick logs

For errors any endpoint can return, see Common errors.

PUT /v1/fs#

Write a storage file (≤ 2 MB; replaces an existing one)

Signature required Kernel only Changes data

The body is the whole file. Parent folders are created; the device writes path~ first and then renames it, so a failure never leaves half a file. Host: stick fs put, stick push, stick www push

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringYespattern ^/length 1–96; ≤ 96 bytesFile

Request body#

text/plain

File content: UTF-8 text, or the raw bytes of a binary file (such as a font)

string; ≤ 2097152 bytes

Examples#

Write an app's entry file#

text/plain
ui.label(ui.root(), {text = sys.date("%H:%M"), font = 48, align = "center"})

Write an app manifest#

name is the app name shown on screen (时钟 = Clock)

text/plain
{"id":"clock","name":"时钟","version":"0.1.0","main":"main.lua"}

Reply#

Written

The file is written

FieldTypeRequiredValuesRangeDescription
okbooleanYestrueAlways true
pathstringYesThe file written
sizeintegerYes≥ 0File size in bytes

Error codes#

StatusCodeDescription
400bad_pathpath is missing or invalid (see path), or names a folder (/ or ending in /)
409is_dirA folder with this name exists
409bad_parentA file in the parent path blocks creating the folder
413too_largeLarger than 2 MB
507no_spaceStorage is full. Delete unused files (see total and used in GET /v1/fs/list)
503no_storageStorage is not mounted. Restart the device; if it persists, check stick logs
500io_errorStorage read/write error. Retry; if it persists, check stick logs

For errors any endpoint can return, see Common errors.

DELETE /v1/fs#

Delete a storage file or folder (recursive=1 deletes its contents)

Signature required Kernel only Changes data

A folder must be empty unless recursive=1. The root cannot be deleted; /apps, /data and /fonts come back empty after deletion

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringYespattern ^/length 1–96; ≤ 96 bytesFile or folder
recursiveinteger0 1; default 01 = delete a folder with everything in it

Reply#

Deleted

Successful reply; endpoints add their own fields

FieldTypeRequiredValuesRangeDescription
okbooleanYestrueAlways true

Error codes#

StatusCodeDescription
400bad_pathpath is missing or invalid (see path), or is the root /
404not_foundNo such file or folder
409not_emptyThe folder is not empty: add recursive=1
503no_storageStorage is not mounted. Restart the device; if it persists, check stick logs
500io_errorStorage read/write error. Retry; if it persists, check stick logs

For errors any endpoint can return, see Common errors.

View the source of this page on GitHub