Imported from RootPlatform/RootSdk.DevKit (
api-samples/server-files/AGENTS.md). Install upstream withnpx skills add RootPlatform/RootSdk.DevKit --skill server-files. Copyright stays with the author.
API Sample: Files
Create, get, list, edit (rename), move, delete, search, and search across the community for files within channel directories.
Source Files
| File | What it covers |
|---|---|
| files.ts | All 8 file methods + 4 events |
SDK Methods
channelFiles.create(request)— upload a file to a directory (requires uploadTokenUri from the platform upload endpoint)channelFiles.get(request)— get a file by IDchannelFiles.list(request)— list files in a directorychannelFiles.edit(request)— rename a file (name is the only mutable field)channelFiles.move(request)— move a file between directorieschannelFiles.delete(request)— delete a filechannelFiles.search(request)— search files within a channel (supports pagination via lastFileId)channelFiles.searchCommunity(request)— search files across multiple channels (results grouped by channel)
Permissions
{
"channel": {
"createFile": true,
"viewFile": true,
"manageFiles": true,
"createMessage": true
}
}
channel.createFile— required for createchannel.viewFile— required for get, list, search, searchCommunitychannel.manageFiles— required for edit, move, deletechannel.createMessage— only for the/server-filescommand trigger
Events
ChannelFileEvent.ChannelFileCreated— file uploaded (includes mimeType, which the entity type does not)ChannelFileEvent.ChannelFileEdited— file renamedChannelFileEvent.ChannelFileDeleted— file deletedChannelFileEvent.ChannelFileMoved— file moved between directories
Apps vs Bots
All code is identical between apps (@rootsdk/server-app) and bots (@rootsdk/server-bot). Only the import statement differs — see the comment at the top of each source file.
Key Behaviors
- uploadTokenUri dependency —
create()requires a raw upload token from the platform's asset upload endpoint. Upload tokens are temporary and should be used promptly, not stored. - Every request requires channelId — files are always scoped to a channel.
- Most requests require directoryId — get, list, edit, delete all need it. Only search and searchCommunity skip it.
- edit() is rename-only — the only mutable field is
name. Usemove()to change directories. - move() requires oldDirectoryId + newDirectoryId — same pattern as channel move.
- search() pagination — pass
lastFileIdto get the next page of results. - searchCommunity() groups results — response contains
results[], each withchannelId,files[], andtotalCount. - length is bigint — file size, not a regular number.
- sha256 is Uint8Array — binary hash, not a hex string.
- mimeType only on created event —
ChannelFileCreatedEventincludesmimeType, but theChannelFileentity does not. - list() is not recursive — returns files in a single directory. List directories first, then list files in each.
- No eventHandlers — unlike channels/access-rules, file methods do not accept an
eventHandlersparameter.