Products · Dash API

Files

Keep files on the phone that only your dot can read, and work with the files Dash gives your dot.

A dot's own data, kept on this device for the signed-in Dash user only. It's never backed up or moved to a new phone, and another user who signs in sees none of it. Keep what matters on the dot's server, and treat this as a copy you can fetch again.

Files live in the dot's own folder, which no other dot sees. Paths are relative to it, such as "receipts/42.pdf", and '' is the folder itself. A call on a path with nothing there fails with missing, while stat gives null for it.

dash.storage.file.read

TypeScript
dash.storage.file.read(path: string, options?: ReadOptions, callOptions?: CallOptions): DashRequest<string>

Reads the file at path, up to 5 MB, as text or base64. Fails with missing if there's no file there.

Types: ReadOptions

dash.storage.file.write

TypeScript
dash.storage.file.write(path: string, data: string, options?: WriteOptions, callOptions?: CallOptions): DashRequest<FileEntry>

Writes data to the file at path, as text or base64, and creates any missing folders above it. Pass { append: true } to add to the end of the file.

Types: WriteOptions, FileEntry

dash.storage.file.stat

TypeScript
dash.storage.file.stat(path: string, callOptions?: CallOptions): DashRequest<FileEntry | null>

Details of the file or folder at path: its kind, size and when it last changed. Gives null if there's nothing there.

Types: FileEntry

dash.storage.file.list

TypeScript
dash.storage.file.list(path?: string, options?: { recursive?: boolean }, callOptions?: CallOptions): DashRequest<FileEntry[]>

What a folder holds, sorted by path. Pass { recursive: true } to include everything in its subfolders.

Types: FileEntry

dash.storage.file.createFolder

TypeScript
dash.storage.file.createFolder(path: string, callOptions?: CallOptions): DashRequest<FileEntry>

Creates a folder at path, with any folders above it that are missing.

Types: FileEntry

dash.storage.file.move

TypeScript
dash.storage.file.move(from: string, to: string, options?: ReplaceOptions, callOptions?: CallOptions): DashRequest<FileEntry>

Moves or renames a file or folder. Pass { overwrite: true } to replace what's already at to.

Types: ReplaceOptions, FileEntry

dash.storage.file.copy

TypeScript
dash.storage.file.copy(from: string, to: string, options?: ReplaceOptions, callOptions?: CallOptions): DashRequest<FileEntry>

Copies a file or folder. Pass { overwrite: true } to replace what's already at to.

Types: ReplaceOptions, FileEntry

dash.storage.file.remove

TypeScript
dash.storage.file.remove(path: string, options?: { recursive?: boolean }, callOptions?: CallOptions): DashRequest<void>

Deletes the file or folder at path. A folder with anything in it needs { recursive: true }.

dash.storage.file.save

TypeScript
dash.storage.file.save(file: DotFile, path: string, options?: ReplaceOptions, callOptions?: CallOptions): DashRequest<FileEntry>

Keeps a temporary file, such as a download, at path.

Types: DotFile, ReplaceOptions, FileEntry

dash.storage.file.open

TypeScript
dash.storage.file.open(path: string, callOptions?: CallOptions): DashRequest<DotFile>

A stored file as a DotFile, to show with its url or send with http.upload.

Types: DotFile

dash.storage.file.usage

TypeScript
dash.storage.file.usage(callOptions?: CallOptions): DashRequest<StorageUsage>

How many bytes the dot's files take, and the most they may take.

Types: StorageUsage

Types

FileEntry

FieldTypeWhat it is
namestring
pathstring
sizenumberIn bytes, and 0 for a folder.
kind'file' | 'folder'
modifiedAtnumberWhen it last changed, in milliseconds since 1 January 1970, as Date.now() gives.
contentType (optional)string

FileEncoding

TypeScript
type FileEncoding = 'text' | 'base64';

StorageUsage

In bytes: what the dot's files take, and the most they may take.

FieldTypeWhat it is
usednumber
quotanumber

ReadOptions

FieldTypeWhat it is
as (optional)FileEncodingDefault: text.

WriteOptions

FieldTypeWhat it is
as (optional)FileEncodingHow data is written. Default: text.
append (optional)booleanAdds to the end of the file in place of replacing it. Default: false.

ReplaceOptions

FieldTypeWhat it is
overwrite (optional)booleanReplaces what's already at the path. Default: false.

DotFile

A file Dash gives your dot, such as a download or a photo. It lasts until the dot closes, unless you save it with dash.storage.file.save.

FieldTypeWhat it is
idstringIdentifies the file to Dash. Pass the whole DotFile to calls, not just its id.
namestring
sizenumberIn bytes.
contentTypestring
urlstringAn address to show the file with, such as an Image's src. It works until the dot closes.

Keep reading