Session files
The files capability uses File Station as the signed-in user: list, create, upload, download and pick files. DSM applies that user’s permissions, and the package account’s rights never replace the caller’s. No administrator setup is needed. Access ends when the browser closes; for offline work use Background jobs or Delegate.
Add it
Section titled “Add it”synopkgland init -t native-go --with files my-filesExisting Go project: synopkgland add files. Both write:
capabilities: files: sessionsession is the only value. files needs a Go backend on x86_64, aarch64 or armv7; a binary backend cannot use it. The Vue UI has a Files page; a plain UI has only the routes.
Use it
Section titled “Use it”Browse and pick in the UI
Section titled “Browse and pick in the UI”The Vue UI has a FileBrowser for shares, folders and files, and NasPicker for a dialog that emits selected; createNasProvider(ctx) from @synopackageland/sdk supplies both with the calls below. Picking a path grants nothing: the backend rechecks the session and permissions on use. See UI components for paths and props.
Call ctx.call(method, params); each call checks that the DSM session belongs to the signed-in user.
| Method | Params | Result |
|---|---|---|
nas.session.status | {} | { mode: "filestation-session" } |
nas.files.shares | { offset } | A page of shares |
nas.files.list | { path, offset, limit, sortBy, sortDirection } | A page of entries |
nas.files.info | { path } | One entry |
nas.files.create_folder | { parent, name } | { created: true } |
limitis 1–100 (default 100);sortByisname,size,typeormtime;sortDirectionisASCorDESC.- A page is
{ files, total, offset }; shares list asshares. An entry is{ path, name, isdir, additional: { size } }. - Paths are absolute and clean (no
.or..), with no backslash, comma, double quote or control character.
Upload and download
Section titled “Upload and download”Files travel as a stream, not JSON; createNasProvider and FileBrowser handle this. Otherwise use ctx.files.endpoint and ctx.files.token():
Upload nas.files.upload | Download nas.files.download | |
|---|---|---|
| Request | POST ?method=nas.files.upload&parent=<folder>&name=<file> | GET or POST ?method=nas.files.download&path=<file> |
| Body | Bytes, application/octet-stream, with Content-Length | None; a POST sends SynoToken as a form field |
| Auth | X-SYNO-TOKEN header and the DSM id cookie | The same session cookie |
| Success | {"success":true,"data":{"uploaded":true}} | The file as an attachment |
Same-origin only. A failed download leaves a truncated file with no JSON error; a lost upload response is commit-uncertain.
Read a file in a handler
Section titled “Read a file in a handler”Register a Go handler with api.HandleRequest, list it in permissions.json as authenticated, and add net/http to the imports of routes.go.
func (cfg Config) readNote(ctx context.Context, caller api.Caller, r *http.Request, params json.RawMessage) (any, error) { var in struct { Folder string `json:"folder"` Relative string `json:"relative"` } if err := decodeParams(params, &in); err != nil { return nil, err } data, err := cfg.SessionFiles.ReadFile(ctx, caller, r, in.Folder, in.Relative) if err != nil { return nil, err } return map[string]any{"bytes": len(data)}, nil}ReadFile reads one regular file below Folder, up to 512 KiB (limit-exceeded above); cfg.SessionFiles.Upload and Download match the streaming calls.
Limits
Section titled “Limits”| Item | Limit |
|---|---|
| Upload size | 16 GiB, with Content-Length (upload_size_required) |
| One request, transfer included | 20 seconds in the generated backend; the UI waits 22 seconds |
offset | At most 1,000,000 |
| Path length | 4096 characters |
ReadFile | 512 KiB |
| Download on DSM 7.1 | No Content-Disposition; a file of at most 4 KiB whose content is a DSM reply (JSON with success) is refused |
| Overwrite, missing parent folder | Not supported |
Troubleshooting
Section titled “Troubleshooting”| Code | Cause | Fix |
|---|---|---|
session_required | No valid DSM session, or another user’s | Sign in again |
dsm_session_required | Standalone login, no DSM id cookie | Sign in on the same host |
denied | File Station refused (DSM 105, 403, 407, 408) | No permission |
upload_size_required | No Content-Length, or over 16 GiB | Send one file under 16 GiB |
commit-uncertain | Upload or folder creation may have failed | Check the folder first |
limit-exceeded | A handler read over 512 KiB | Read less or stream |
unknown_method | Built without the files capability | Run synopkgland add files |
admin_required, app_privilege_denied | permissions.json or entry refused | See Native apps |
Other codes are in Errors; a package-account share is in Shared folder.