DocsReferenceAPI reference

microSD card

Files on the microSD card (FAT). Read and written in chunks of ≤ 1 MB per request (256 KB on the host), resumable. Leave existing files on the card alone; put your own under /stick/

GET /v1/sd/list#

List a folder on the microSD card (up to 256 entries)

Signature required Kernel only

Lists the files and subfolders one level deep, with the card total and used bytes. Temp files x~ left by interrupted uploads are listed too

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringpattern ^/length 1–160; ≤ 160 bytesFolder; the card 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/sd
503no_cardNo card, the card is not FAT, or a mount was just tried (retry in 2 s); message says which
500io_errorCard read/write error; the device unmounted the card and remounts on the next request. Retry

For errors any endpoint can return, see Common errors.

GET /v1/sd#

Read a card file in chunks (≤ 1 MB per request)

Signature required Kernel only

The reply is the raw bytes of [offset, offset+length); the X-Size header is the file size. The host reads 256 KB chunks up to X-Size and resumes from the bytes it already has (stick sd get does this). If the device fails part way it can only drop the connection; re-read a short chunk

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringYespattern ^/length 1–160; ≤ 160 bytesFile
offsetinteger0–2147483647Start byte; 0 when omitted
lengthinteger0–1048576Byte count; up to 1 MB when omitted or larger (never past the end of the file)

Reply#

Bytes of this part of the file

The reply is binary.

application/octet-stream

Error codes#

StatusCodeDescription
400bad_pathpath is missing or invalid (see path)
400bad_argsoffset or length is not a non-negative integer
416bad_offsetoffset is past the end of the file (400 when over 2 GB)
404not_foundNo such file
400is_dirpath is a folder. List it with GET /v1/sd/list
503no_cardNo card, the card is not FAT, or a mount was just tried (retry in 2 s); message says which
500io_errorCard read/write error; the device unmounted the card and remounts on the next request. Retry

For errors any endpoint can return, see Common errors.

PUT /v1/sd#

Write a card file in chunks (≤ 1 MB each, resumable)

Signature required Kernel only Changes data

Each chunk goes into the temp file path~ at offset: offset=0 starts it, later offsets must equal the bytes written so far; final=1 then renames path~ to path (replacing an existing file). Omitting both offset and final uploads a small file in one go. Parent folders are created. If a chunk arrives incomplete or its hash mismatches, the temp file is cut back to offset; resend from offset. The host uses 256 KB chunks (stick sd put, which also uploads folders)

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringYespattern ^/length 1–160; ≤ 160 bytesFile
offsetinteger0–2147483647Start byte of this chunk in the file
finalinteger0 11 = last chunk; rename when written

Request body#

application/octet-stream

Bytes of this chunk

Examples#

Small file in one go#

offset and final omitted; the content is hello and a newline

HEX
68656c6c6f0a

First chunk of a large file#

offset=0 starts big.tl~; real chunks are 256 KB, 6 bytes shown here

HEX
000001040400

Resume with the last chunk#

262144 bytes already written; final=1 renames it to big.tl

HEX
1e0002040000

Reply#

Chunk written

The chunk is in the temp file; when done, it was renamed to the final file

FieldTypeRequiredValuesRangeDescription
okbooleanYestrueAlways true
pathstringYesThe file (without ~)
sizeintegerYes≥ 0Total bytes written so far; the offset of the next chunk
donebooleanYestrue = renamed to path, upload complete; false = still in the temp file path~

Error codes#

StatusCodeDescription
400bad_pathpath is missing or invalid (see path), or names a folder (/ or ending in /)
400bad_argsoffset is not a non-negative integer, or final is not 0 / 1
409bad_offsetoffset differs from the temp file's current size; the reply also carries size (the current size), resume from there. 400 when offset is over 2 GB. See the example “Resume with the last chunk” for the correct form
413too_largeThe chunk is larger than 1 MB
409is_dirA folder with this name exists
409bad_parentA file in the parent path blocks creating the folder
507no_spaceThe card is full; the temp file was deleted
503no_cardNo card, the card is not FAT, or a mount was just tried (retry in 2 s); message says which
500io_errorCard read/write error; the device unmounted the card and remounts on the next request. Retry

For errors any endpoint can return, see Common errors.

DELETE /v1/sd#

Delete a card 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. Leave existing files on the card alone and delete only your own (kept under /stick/)

Parameters#

ParameterTypeRequiredValuesRangeDescription
pathstringYespattern ^/length 1–160; ≤ 160 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_cardNo card, the card is not FAT, or a mount was just tried (retry in 2 s); message says which
500io_errorCard read/write error; the device unmounted the card and remounts on the next request. Retry

For errors any endpoint can return, see Common errors.

View the source of this page on GitHub