Skip to content
Syno Package Land
Language: English

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.

Terminal window
synopkgland init -t native-go --with files my-files

Existing Go project: synopkgland add files. Both write:

capabilities:
files: session

session 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.

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.

MethodParamsResult
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 }
  • limit is 1–100 (default 100); sortBy is name, size, type or mtime; sortDirection is ASC or DESC.
  • A page is { files, total, offset }; shares list as shares. An entry is { path, name, isdir, additional: { size } }.
  • Paths are absolute and clean (no . or ..), with no backslash, comma, double quote or control character.

Files travel as a stream, not JSON; createNasProvider and FileBrowser handle this. Otherwise use ctx.files.endpoint and ctx.files.token():

Upload nas.files.uploadDownload nas.files.download
RequestPOST ?method=nas.files.upload&parent=<folder>&name=<file>GET or POST ?method=nas.files.download&path=<file>
BodyBytes, application/octet-stream, with Content-LengthNone; a POST sends SynoToken as a form field
AuthX-SYNO-TOKEN header and the DSM id cookieThe 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.

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.

ItemLimit
Upload size16 GiB, with Content-Length (upload_size_required)
One request, transfer included20 seconds in the generated backend; the UI waits 22 seconds
offsetAt most 1,000,000
Path length4096 characters
ReadFile512 KiB
Download on DSM 7.1No Content-Disposition; a file of at most 4 KiB whose content is a DSM reply (JSON with success) is refused
Overwrite, missing parent folderNot supported
CodeCauseFix
session_requiredNo valid DSM session, or another user’sSign in again
dsm_session_requiredStandalone login, no DSM id cookieSign in on the same host
deniedFile Station refused (DSM 105, 403, 407, 408)No permission
upload_size_requiredNo Content-Length, or over 16 GiBSend one file under 16 GiB
commit-uncertainUpload or folder creation may have failedCheck the folder first
limit-exceededA handler read over 512 KiBRead less or stream
unknown_methodBuilt without the files capabilityRun synopkgland add files
admin_required, app_privilege_deniedpermissions.json or entry refusedSee Native apps

Other codes are in Errors; a package-account share is in Shared folder.