@xano/developer-mcp 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tools/index.d.ts +1 -3
- package/dist/tools/xanoscript_docs.d.ts +1 -3
- package/dist/tools/xanoscript_docs.js +4 -4
- package/dist/xanoscript.d.ts +8 -0
- package/dist/xanoscript.js +43 -3
- package/dist/xanoscript_docs/README.md +1 -0
- package/dist/xanoscript_docs/docs_index.json +17 -4
- package/dist/xanoscript_docs/essentials.md +27 -0
- package/dist/xanoscript_docs/file-uploads.md +408 -0
- package/dist/xanoscript_docs/integrations/utilities.md +61 -21
- package/dist/xanoscript_docs/types.md +12 -1
- package/dist/xanoscript_docs/version.json +1 -1
- package/package.json +1 -1
package/dist/tools/index.d.ts
CHANGED
|
@@ -35,9 +35,7 @@ export declare const toolSpecs: {
|
|
|
35
35
|
warnings: z.ZodOptional<z.ZodNumber>;
|
|
36
36
|
}>;
|
|
37
37
|
readonly xano_xanoscript_docs: BuiltTool<{
|
|
38
|
-
topic: z.ZodOptional<z.
|
|
39
|
-
[x: string]: string;
|
|
40
|
-
}>>;
|
|
38
|
+
topic: z.ZodOptional<z.ZodString>;
|
|
41
39
|
file_path: z.ZodOptional<z.ZodString>;
|
|
42
40
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
43
41
|
index: "index";
|
|
@@ -52,9 +52,7 @@ export declare function xanoscriptDocs(args?: XanoscriptDocsArgs): XanoscriptDoc
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function xanoscriptDocsTool(args?: XanoscriptDocsArgs): ToolResult;
|
|
54
54
|
export declare const xanoscriptDocsToolSpec: import("./define_tool.js").BuiltTool<{
|
|
55
|
-
topic: z.ZodOptional<z.
|
|
56
|
-
[x: string]: string;
|
|
57
|
-
}>>;
|
|
55
|
+
topic: z.ZodOptional<z.ZodString>;
|
|
58
56
|
file_path: z.ZodOptional<z.ZodString>;
|
|
59
57
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
60
58
|
index: "index";
|
|
@@ -8,7 +8,7 @@ import { readFileSync } from "fs";
|
|
|
8
8
|
import { dirname, join } from "path";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { z } from "zod";
|
|
11
|
-
import { readXanoscriptDocsV2, readXanoscriptDocsStructured, getXanoscriptDocsVersion,
|
|
11
|
+
import { readXanoscriptDocsV2, readXanoscriptDocsStructured, getXanoscriptDocsVersion, getTopicDescriptions, getTierFacts, } from "../xanoscript.js";
|
|
12
12
|
import { defineTool } from "./define_tool.js";
|
|
13
13
|
// =============================================================================
|
|
14
14
|
// Path Resolution
|
|
@@ -156,7 +156,6 @@ export function xanoscriptDocsTool(args) {
|
|
|
156
156
|
// =============================================================================
|
|
157
157
|
// MCP Tool Definition
|
|
158
158
|
// =============================================================================
|
|
159
|
-
const topicEnumValues = getTopicNames();
|
|
160
159
|
// Derive tier size facts from the actual files so the advertised numbers can
|
|
161
160
|
// never drift stale (see getTierFacts). Computed once at module load.
|
|
162
161
|
const tierFacts = getTierFacts(getXanoscriptDocsPath());
|
|
@@ -177,10 +176,11 @@ export const xanoscriptDocsToolSpec = defineTool({
|
|
|
177
176
|
},
|
|
178
177
|
inputShape: {
|
|
179
178
|
topic: z
|
|
180
|
-
.
|
|
179
|
+
.string()
|
|
181
180
|
.optional()
|
|
182
181
|
.describe("Documentation topic to retrieve. Call without any parameters to get the compact topic index; use topic='readme' for the full prose overview. " +
|
|
183
|
-
"Example: topic='syntax' for language syntax, topic='database' for database operations, topic='types' for type system
|
|
182
|
+
"Example: topic='syntax' for language syntax, topic='database' for database operations, topic='types' for type system. " +
|
|
183
|
+
"Common synonyms are accepted and resolved automatically (e.g. 'upload'/'storage' -> 'file-uploads'); an unrecognized topic returns the list of valid topics.\n\n" +
|
|
184
184
|
"Available topics:\n" +
|
|
185
185
|
getTopicDescriptions()),
|
|
186
186
|
file_path: z
|
package/dist/xanoscript.d.ts
CHANGED
|
@@ -24,6 +24,14 @@ export interface XanoscriptDocsArgs {
|
|
|
24
24
|
exclude_topics?: string[];
|
|
25
25
|
}
|
|
26
26
|
export declare const XANOSCRIPT_DOCS_V2: Record<string, DocConfig>;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a topic name or alias to a canonical topic name. Returns the input
|
|
29
|
+
* unchanged when it is already canonical or unknown, so callers can still
|
|
30
|
+
* surface the existing "Unknown topic" error for genuinely bad input.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveTopic(input?: string): string | undefined;
|
|
33
|
+
/** Get all alias names (keys of the alias -> canonical topic map). */
|
|
34
|
+
export declare function getAliasNames(): string[];
|
|
27
35
|
/**
|
|
28
36
|
* Clear all cached documentation content and version data.
|
|
29
37
|
* Useful for testing or when docs files change at runtime.
|
package/dist/xanoscript.js
CHANGED
|
@@ -24,6 +24,45 @@ function buildDocsConfig() {
|
|
|
24
24
|
return config;
|
|
25
25
|
}
|
|
26
26
|
export const XANOSCRIPT_DOCS_V2 = buildDocsConfig();
|
|
27
|
+
/**
|
|
28
|
+
* Map of alias -> canonical topic name, built from the `aliases` arrays in
|
|
29
|
+
* docs_index.json. Lets callers pass a natural synonym (e.g. "upload",
|
|
30
|
+
* "storage", "attachment") and have it resolve to the canonical topic
|
|
31
|
+
* ("file-uploads"). An alias that shadows a real topic name is skipped, and
|
|
32
|
+
* cross-topic collisions are resolved first-writer-wins.
|
|
33
|
+
*/
|
|
34
|
+
const ALIAS_TO_TOPIC = (() => {
|
|
35
|
+
const map = {};
|
|
36
|
+
for (const [key, topic] of Object.entries(docsIndex.topics)) {
|
|
37
|
+
const aliases = topic.aliases;
|
|
38
|
+
if (!aliases)
|
|
39
|
+
continue;
|
|
40
|
+
for (const alias of aliases) {
|
|
41
|
+
if (alias in XANOSCRIPT_DOCS_V2)
|
|
42
|
+
continue; // never shadow a canonical topic name
|
|
43
|
+
if (alias in map)
|
|
44
|
+
continue; // first-writer-wins on cross-topic collisions
|
|
45
|
+
map[alias] = key;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return map;
|
|
49
|
+
})();
|
|
50
|
+
/**
|
|
51
|
+
* Resolve a topic name or alias to a canonical topic name. Returns the input
|
|
52
|
+
* unchanged when it is already canonical or unknown, so callers can still
|
|
53
|
+
* surface the existing "Unknown topic" error for genuinely bad input.
|
|
54
|
+
*/
|
|
55
|
+
export function resolveTopic(input) {
|
|
56
|
+
if (!input)
|
|
57
|
+
return input;
|
|
58
|
+
if (input in XANOSCRIPT_DOCS_V2)
|
|
59
|
+
return input;
|
|
60
|
+
return ALIAS_TO_TOPIC[input] ?? input;
|
|
61
|
+
}
|
|
62
|
+
/** Get all alias names (keys of the alias -> canonical topic map). */
|
|
63
|
+
export function getAliasNames() {
|
|
64
|
+
return Object.keys(ALIAS_TO_TOPIC);
|
|
65
|
+
}
|
|
27
66
|
// =============================================================================
|
|
28
67
|
// Content Cache
|
|
29
68
|
// =============================================================================
|
|
@@ -257,15 +296,16 @@ export function readXanoscriptDocsV2(docsPath, args) {
|
|
|
257
296
|
const header = `# XanoScript Documentation for: ${args.file_path}\n\nMatched topics: ${topics.join(", ")}\nMode: ${mode}\nVersion: ${version}\n\n---\n\n`;
|
|
258
297
|
return header + docs.join("\n\n---\n\n");
|
|
259
298
|
}
|
|
260
|
-
// Topic-based: return specific doc
|
|
261
|
-
const
|
|
299
|
+
// Topic-based: return specific doc (resolve aliases to canonical names first)
|
|
300
|
+
const canonicalTopic = resolveTopic(args.topic);
|
|
301
|
+
const config = XANOSCRIPT_DOCS_V2[canonicalTopic];
|
|
262
302
|
if (!config) {
|
|
263
303
|
const availableTopics = Object.keys(XANOSCRIPT_DOCS_V2).join(", ");
|
|
264
304
|
throw new Error(`Unknown topic "${args.topic}".\n\nAvailable topics: ${availableTopics}`);
|
|
265
305
|
}
|
|
266
306
|
const content = cachedReadFile(join(docsPath, config.file));
|
|
267
307
|
const doc = mode === "quick_reference"
|
|
268
|
-
? extractQuickReference(content,
|
|
308
|
+
? extractQuickReference(content, canonicalTopic)
|
|
269
309
|
: content;
|
|
270
310
|
return `${doc}\n\n---\nDocumentation version: ${version}`;
|
|
271
311
|
}
|
|
@@ -238,6 +238,7 @@ Use `xano_xanoscript_docs({ tier: "survival" })` or `xano_xanoscript_docs({ tier
|
|
|
238
238
|
| Topic | Description | Key Sections |
|
|
239
239
|
| ---------- | --------------------------------------------------------------- | ------------ |
|
|
240
240
|
| `apis` | HTTP endpoint definitions with authentication and CRUD patterns | Decision Tree, CRUD Examples |
|
|
241
|
+
| `file-uploads` | Uploading files to native Xano storage | `file?` input, create_attachment, signed URLs |
|
|
241
242
|
| `tasks` | Scheduled and cron jobs | Cron Syntax, Input Handling |
|
|
242
243
|
| `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) | Predefined Inputs, Event Types |
|
|
243
244
|
| `realtime` | Real-time channels and events for push updates | Channels, Events |
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.3.0",
|
|
3
3
|
"description": "Machine-readable index for XanoScript documentation (version mirrors version.json)",
|
|
4
4
|
|
|
5
5
|
"topics": {
|
|
@@ -147,9 +147,9 @@
|
|
|
147
147
|
},
|
|
148
148
|
"integrations/cloud-storage": {
|
|
149
149
|
"file": "integrations/cloud-storage.md",
|
|
150
|
-
"description": "AWS S3, Azure Blob, and GCP Storage operations",
|
|
150
|
+
"description": "AWS S3, Azure Blob, and GCP Storage operations (external buckets, not native Xano storage)",
|
|
151
151
|
"applyTo": [],
|
|
152
|
-
"aliases": ["s3", "azure", "gcp", "
|
|
152
|
+
"aliases": ["s3", "azure", "gcp", "external-storage", "bucket"]
|
|
153
153
|
},
|
|
154
154
|
"integrations/search": {
|
|
155
155
|
"file": "integrations/search.md",
|
|
@@ -175,6 +175,13 @@
|
|
|
175
175
|
"applyTo": [],
|
|
176
176
|
"aliases": ["email", "zip", "lambda", "archive"]
|
|
177
177
|
},
|
|
178
|
+
"file-uploads": {
|
|
179
|
+
"file": "file-uploads.md",
|
|
180
|
+
"description": "Uploading files to native Xano storage: file? input, create_attachment, sign_private_url",
|
|
181
|
+
"applyTo": [],
|
|
182
|
+
"priority": 9,
|
|
183
|
+
"aliases": ["file-upload", "upload", "uploads", "attachment", "attachments", "file", "files", "private-storage", "storage", "multipart"]
|
|
184
|
+
},
|
|
178
185
|
"frontend": {
|
|
179
186
|
"file": "frontend.md",
|
|
180
187
|
"description": "Static frontend development and deployment",
|
|
@@ -369,6 +376,12 @@
|
|
|
369
376
|
"util.get_env": { "file": "integrations/utilities.md" },
|
|
370
377
|
"util.get_all_input": { "file": "integrations/utilities.md" },
|
|
371
378
|
"util.get_input": { "file": "integrations/utilities.md" },
|
|
379
|
+
"storage.create_attachment": { "file": "file-uploads.md" },
|
|
380
|
+
"storage.create_image": { "file": "file-uploads.md" },
|
|
381
|
+
"storage.sign_private_url": { "file": "file-uploads.md" },
|
|
382
|
+
"storage.create_file_resource": { "file": "integrations/utilities.md" },
|
|
383
|
+
"storage.read_file_resource": { "file": "integrations/utilities.md" },
|
|
384
|
+
"storage.delete_file": { "file": "integrations/utilities.md" },
|
|
372
385
|
"cloud.aws.s3.upload_file": { "file": "integrations/cloud-storage.md" },
|
|
373
386
|
"cloud.aws.s3.read_file": { "file": "integrations/cloud-storage.md" },
|
|
374
387
|
"cloud.aws.s3.sign_url": { "file": "integrations/cloud-storage.md" },
|
|
@@ -398,7 +411,7 @@
|
|
|
398
411
|
"rate_limiting": ["security.md", "integrations/redis.md"],
|
|
399
412
|
"error_handling": ["syntax.md", "essentials.md"],
|
|
400
413
|
"pagination": ["database.md", "apis.md"],
|
|
401
|
-
"file_upload": ["integrations/cloud-storage.md", "streaming.md"],
|
|
414
|
+
"file_upload": ["file-uploads.md", "integrations/cloud-storage.md", "streaming.md"],
|
|
402
415
|
"caching": ["performance.md", "integrations/redis.md"],
|
|
403
416
|
"search": ["integrations/search.md"],
|
|
404
417
|
"email": ["integrations/utilities.md"],
|
|
@@ -640,6 +640,32 @@ Each `.xs` file must contain exactly **one** construct. Placing two constructs i
|
|
|
640
640
|
// function/helper_b.xs -> contains only "helper_b"
|
|
641
641
|
```
|
|
642
642
|
|
|
643
|
+
### 14. Using `image?` for file uploads (the `.path` footgun)
|
|
644
|
+
|
|
645
|
+
Upload inputs **must** be typed `file?`. `image?`/`attachment?`/`video?`/`audio?` pass the raw upload object (which has `tmp_name` but no `.path`), so `storage.*` fails at runtime with `Missing param: path`. The validator does **not** catch this — it is syntactically valid.
|
|
646
|
+
|
|
647
|
+
```xs
|
|
648
|
+
// Wrong - image? input; storage op fails with "Missing param: path"
|
|
649
|
+
// input { image? photo }
|
|
650
|
+
// storage.create_image { value = $input.photo } as $f
|
|
651
|
+
|
|
652
|
+
// Also wrong - hand-setting .path from a hallucinated .tmp_name property
|
|
653
|
+
// |set:"path":$input.photo.tmp_name
|
|
654
|
+
|
|
655
|
+
// Correct - file? input populates .path; create_attachment accepts any type
|
|
656
|
+
// (value, access, and filename are all required on storage.create_attachment)
|
|
657
|
+
stack {
|
|
658
|
+
storage.create_attachment {
|
|
659
|
+
value = $input.photo
|
|
660
|
+
access = "private"
|
|
661
|
+
filename = $input.photo.name
|
|
662
|
+
} as $f
|
|
663
|
+
}
|
|
664
|
+
// input { file? photo }
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
See `xano_xanoscript_docs({ topic: "file-uploads" })` for the full pattern.
|
|
668
|
+
|
|
643
669
|
---
|
|
644
670
|
|
|
645
671
|
## Related Topics
|
|
@@ -653,5 +679,6 @@ Explore more with `xano_xanoscript_docs({ topic: "<topic>" })`:
|
|
|
653
679
|
| `database` | All db.* operations: query, get, add, edit, delete |
|
|
654
680
|
| `functions` | Reusable function stacks, async patterns, loops |
|
|
655
681
|
| `apis` | HTTP endpoints, authentication, CRUD patterns |
|
|
682
|
+
| `file-uploads` | Uploading files to Xano storage (`file?`, create_attachment, signed URLs) |
|
|
656
683
|
| `security` | Security best practices and authentication |
|
|
657
684
|
| `integrations` | External API patterns (OpenAI, Stripe, etc.) |
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "api/**/*.xs, function/**/*.xs"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# File Uploads (Native Xano Storage)
|
|
6
|
+
|
|
7
|
+
> **TL;DR:** To accept an uploaded file, declare the input as `file?` — **never** `image?`. Only `file` pre-processes the upload and populates `.path`; `image`/`attachment`/`video`/`audio` pass the raw upload object and every `storage.*` op then fails with `Missing param: path` (HTTP 400). Store with `storage.create_attachment` (accepts any file type), save the result to an `attachment?`/`image?` column, then return a viewable link: `storage.sign_private_url` for **private** files, or the instance URL + `.path` for **public** files.
|
|
8
|
+
|
|
9
|
+
This topic covers uploading files **to Xano's own private/public storage** (the vault). For pushing files to external buckets (AWS S3, Azure Blob, GCP Storage), see `integrations/cloud-storage` instead.
|
|
10
|
+
|
|
11
|
+
> **Comment syntax note:** XanoScript comments use `//` only (never `#`), and `//` is valid **only on its own line at the `input {}` / `stack {}` / top level — never inside an operation's `{ ... }` argument block and never as a trailing same-line comment**. Putting a comment inside `storage.create_attachment { ... }` or after `file? photo` is a parse error. Every example below follows this rule.
|
|
12
|
+
|
|
13
|
+
## Quick Reference
|
|
14
|
+
|
|
15
|
+
| Concern | Correct | Wrong |
|
|
16
|
+
|---------|---------|-------|
|
|
17
|
+
| Input type for an upload | `file? my_file` / `file[]? my_files` | `image?`, `attachment?`, `video?`, `audio?` |
|
|
18
|
+
| Storage op for any file type (PDF, HEIC, …) | `storage.create_attachment` | `storage.create_image` (image extensions only) |
|
|
19
|
+
| Storage op for images only (JPEG/PNG/GIF/WEBP) | `storage.create_image` | — |
|
|
20
|
+
| Reading the stored path | `$stored_file.path` | `$input.my_file.tmp_name`, `.path` (not real input properties) |
|
|
21
|
+
| Viewing a **private** file | `storage.sign_private_url` (pathname + ttl, one arg per line) | reading `.path` directly (returns HTTP 403) |
|
|
22
|
+
| Viewing a **public** file | instance base URL `~ $stored_file.path` (no signing) | `storage.sign_private_url` (works but is unnecessary) |
|
|
23
|
+
| Multiple-file form field | append as `field[]` (e.g. `photos[]`) | append repeatedly as `photos` (only the last file is kept) |
|
|
24
|
+
| Required `storage.*` args | always pass `value`, `access`, **and** `filename` | omitting `access` or `filename` (validation error) |
|
|
25
|
+
| Frontend `Content-Type` | let the browser set it | manually setting `multipart/form-data` |
|
|
26
|
+
|
|
27
|
+
## The Core Rule: `file?`, not `image?`
|
|
28
|
+
|
|
29
|
+
When the input is declared `image?` (or `video?`/`audio?`/`attachment?`), Xano hands your stack the raw upload object, which does **not** have a populated `.path`. Xano detects the missing `.path` at the **input-parsing layer**, before your stack even runs, so every upload fails:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
Status 400 Bad Request
|
|
33
|
+
{ "code": "ERROR_CODE_INPUT_ERROR", "message": "Missing param: path",
|
|
34
|
+
"payload": { "param": "my_file.path" } }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Because this fires before the stack runs, no in-stack workaround (e.g. copying `tmp_name` into `.path`) can rescue it — see Common Mistakes. When the input is declared `file?`, Xano pre-processes the multipart upload and sets `.path` **before the stack runs**. This is the single fix for `Missing param: path`.
|
|
38
|
+
|
|
39
|
+
> The input type names (`image`, `video`, `audio`, `attachment`, `file`) look like semantic choices but are technical: **only `file` populates `.path` on a multipart upload.** Use `file?` universally for uploads regardless of what kind of file you expect.
|
|
40
|
+
|
|
41
|
+
### Input type forms
|
|
42
|
+
|
|
43
|
+
```xs
|
|
44
|
+
// single file, optional
|
|
45
|
+
file? my_file
|
|
46
|
+
// single file, required
|
|
47
|
+
file my_file
|
|
48
|
+
// multiple files, optional array
|
|
49
|
+
file[]? my_files
|
|
50
|
+
// multiple files, required array
|
|
51
|
+
file[] my_files
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Storage Operations
|
|
55
|
+
|
|
56
|
+
All `storage.create_*` operations require three arguments — `value`, `access`, and `filename` — written one per line (block arguments are newline-separated; commas are only used inside object literals like `data = { ... }`).
|
|
57
|
+
|
|
58
|
+
### `storage.create_attachment` — any file type (recommended default)
|
|
59
|
+
|
|
60
|
+
```xs
|
|
61
|
+
storage.create_attachment {
|
|
62
|
+
value = $input.my_file
|
|
63
|
+
access = "private"
|
|
64
|
+
filename = $input.my_file.name
|
|
65
|
+
} as $stored_file
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Accepts images, PDFs, HEIC, and any other file type. Use this for documents, receipts, mixed uploads — anything where the file type is not guaranteed to be an image. Set `access` to `"private"` (default for sensitive data) or `"public"`.
|
|
69
|
+
|
|
70
|
+
### `storage.create_image` — images only
|
|
71
|
+
|
|
72
|
+
```xs
|
|
73
|
+
storage.create_image {
|
|
74
|
+
value = $input.my_file
|
|
75
|
+
access = "private"
|
|
76
|
+
filename = $input.my_file.name
|
|
77
|
+
} as $stored_file
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Validates the extension internally and **only accepts JPEG, PNG, GIF, WEBP**. A PDF or HEIC upload returns `Invalid file extension.` (HTTP 500, `code: ERROR_FATAL`). Only use when you are certain the upload will always be one of those image formats; otherwise prefer `storage.create_attachment`.
|
|
81
|
+
|
|
82
|
+
### The stored-file object
|
|
83
|
+
|
|
84
|
+
Both ops return an object with this shape (verified against a live workspace):
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
{
|
|
88
|
+
"access": "private", // or "public" — the access you passed
|
|
89
|
+
"path": "/vault/Xq9lrwqH/.../doc.pdf",
|
|
90
|
+
"name": "doc.pdf",
|
|
91
|
+
"type": "image" | "pdf" | "video" | "audio" | ...,
|
|
92
|
+
"size": 303, // bytes
|
|
93
|
+
"mime": "application/pdf", // full MIME type
|
|
94
|
+
"meta": { "validated": false } // images add "width" and "height"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`.path` is the permanent Xano vault path. Use it everywhere — in the DB record, in `sign_private_url`, and in responses. Save the **whole object** into an `attachment?`/`image?` column (not just the path) so the metadata is preserved.
|
|
99
|
+
|
|
100
|
+
### Viewing a private file — `storage.sign_private_url`
|
|
101
|
+
|
|
102
|
+
A `private` file is **not** directly reachable: requesting its `.path` without a signature returns HTTP 403. Generate a time-limited signed URL to display or download it:
|
|
103
|
+
|
|
104
|
+
```xs
|
|
105
|
+
storage.sign_private_url {
|
|
106
|
+
pathname = $stored_file.path
|
|
107
|
+
ttl = 3600
|
|
108
|
+
} as $signed_url
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`pathname` is the stored `.path` (use `$record.file.path` after reading the record back from the database). `ttl` is the lifetime in seconds, so `3600` = 1 hour; the URL stops working once it expires.
|
|
112
|
+
|
|
113
|
+
### Viewing a public file — no signing needed
|
|
114
|
+
|
|
115
|
+
A file stored with `access = "public"` is served **directly** at your instance's base URL followed by the stored `.path` (no signing, valid until the file is deleted). The stored object has **no** `url` field, so build the URL from `.path`:
|
|
116
|
+
|
|
117
|
+
```xs
|
|
118
|
+
storage.create_attachment {
|
|
119
|
+
value = $input.my_file
|
|
120
|
+
access = "public"
|
|
121
|
+
filename = $input.my_file.name
|
|
122
|
+
} as $stored_file
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Then return the path and let the client prepend its base URL, or build the absolute URL server-side (set `PUBLIC_BASE_URL` to your instance origin, e.g. `https://your-instance.xano.io`, in workspace env vars):
|
|
126
|
+
|
|
127
|
+
```xs
|
|
128
|
+
response = {
|
|
129
|
+
path : $stored_file.path
|
|
130
|
+
public_url: ($env.PUBLIC_BASE_URL ~ $stored_file.path)
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Use `public` only for non-sensitive assets (anyone with the URL can access it). Use `private` + `sign_private_url` for anything access-controlled.
|
|
135
|
+
|
|
136
|
+
### Serving a generated file (not an upload)
|
|
137
|
+
|
|
138
|
+
To serve a file you build in the stack (CSV/JSON/zip export, etc.), create it with `storage.create_file_resource`, then **store** it with `storage.create_attachment` to get a vault `.path`. The `create_file_resource` result is an internal file-resource token — it has **no** servable URL/path of its own.
|
|
139
|
+
|
|
140
|
+
```xs
|
|
141
|
+
storage.create_file_resource {
|
|
142
|
+
filename = "export.csv"
|
|
143
|
+
filedata = $csv_content
|
|
144
|
+
} as $resource
|
|
145
|
+
storage.create_attachment {
|
|
146
|
+
value = $resource
|
|
147
|
+
access = "public"
|
|
148
|
+
filename = "export.csv"
|
|
149
|
+
} as $stored_file
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Then serve `$stored_file` like any uploaded file: instance URL + `.path` for `public`, or `storage.sign_private_url` for `private`. See `integrations/utilities` for `create_file_resource` and zip/CSV details.
|
|
153
|
+
|
|
154
|
+
## Complete Single-Upload Pattern
|
|
155
|
+
|
|
156
|
+
This is the full, end-to-end flow validated against a live Xano workspace (`file?` input → `storage.create_attachment` → `db.add` → `storage.sign_private_url`):
|
|
157
|
+
|
|
158
|
+
```xs
|
|
159
|
+
query upload verb=POST {
|
|
160
|
+
api_group = "FileUploadDemo"
|
|
161
|
+
input {
|
|
162
|
+
text? name? filters=trim
|
|
163
|
+
// MUST be `file?` — only `file` populates `.path` on a multipart upload.
|
|
164
|
+
file? document
|
|
165
|
+
}
|
|
166
|
+
stack {
|
|
167
|
+
precondition ($input.document != null) {
|
|
168
|
+
error_type = "inputerror"
|
|
169
|
+
error = "Provide a file in the `document` field."
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// create_attachment accepts any file type (PDF, HEIC, etc.).
|
|
173
|
+
storage.create_attachment {
|
|
174
|
+
value = $input.document
|
|
175
|
+
access = "private"
|
|
176
|
+
filename = $input.document.name
|
|
177
|
+
} as $stored_file
|
|
178
|
+
|
|
179
|
+
db.add upload_demo_file {
|
|
180
|
+
data = {
|
|
181
|
+
created_at: "now"
|
|
182
|
+
name : $input.name
|
|
183
|
+
file : $stored_file
|
|
184
|
+
}
|
|
185
|
+
} as $rec
|
|
186
|
+
|
|
187
|
+
storage.sign_private_url {
|
|
188
|
+
pathname = $rec.file.path
|
|
189
|
+
ttl = 3600
|
|
190
|
+
} as $signed_url
|
|
191
|
+
}
|
|
192
|
+
response = {
|
|
193
|
+
id : $rec.id
|
|
194
|
+
name : $rec.name
|
|
195
|
+
path : $rec.file.path
|
|
196
|
+
size : $rec.file.size
|
|
197
|
+
signed_url: $signed_url
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Complete Multiple-Upload Pattern
|
|
203
|
+
|
|
204
|
+
Declare the input `file[]?` and loop with `foreach`/`each as`. **The multipart field name must be sent with a `[]` suffix** (e.g. `photos[]`) for Xano to collect repeated parts into the array — see the frontend note below.
|
|
205
|
+
|
|
206
|
+
```xs
|
|
207
|
+
query upload_many verb=POST {
|
|
208
|
+
api_group = "FileUploadDemo"
|
|
209
|
+
input {
|
|
210
|
+
text item_id
|
|
211
|
+
file[]? photos?
|
|
212
|
+
}
|
|
213
|
+
stack {
|
|
214
|
+
var $created { value = [] }
|
|
215
|
+
conditional {
|
|
216
|
+
if ($input.photos != null && ($input.photos|count) > 0) {
|
|
217
|
+
foreach ($input.photos) {
|
|
218
|
+
each as $file {
|
|
219
|
+
storage.create_attachment {
|
|
220
|
+
value = $file
|
|
221
|
+
access = "private"
|
|
222
|
+
filename = $file.name
|
|
223
|
+
} as $stored_file
|
|
224
|
+
db.add item_photo {
|
|
225
|
+
data = {
|
|
226
|
+
item_id: $input.item_id
|
|
227
|
+
file : $stored_file
|
|
228
|
+
}
|
|
229
|
+
} as $new_photo
|
|
230
|
+
var.update $created {
|
|
231
|
+
value = $created|push:{ id: $new_photo.id, path: $new_photo.file.path }
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
response = {
|
|
239
|
+
count : $created|count
|
|
240
|
+
created: $created
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Table Schema for Stored Files
|
|
246
|
+
|
|
247
|
+
Store the file metadata object in an `attachment?` (or `image?`) column. Despite the names, both column types store the identical JSON structure (`access`, `path`, `name`, `type`, `size`, `mime`, `meta`), and both accept the result of `storage.create_attachment` **and** `storage.create_image` — there is no type mismatch at the data layer (verified live: an `image?` column accepts a `create_attachment` result and vice-versa).
|
|
248
|
+
|
|
249
|
+
```xs
|
|
250
|
+
table upload_demo_file {
|
|
251
|
+
auth = false
|
|
252
|
+
schema {
|
|
253
|
+
int id
|
|
254
|
+
timestamp created_at?=now
|
|
255
|
+
text? name? filters=trim
|
|
256
|
+
// File metadata from storage.create_attachment / storage.create_image.
|
|
257
|
+
attachment? file?
|
|
258
|
+
}
|
|
259
|
+
index = [
|
|
260
|
+
{type: "primary", field: [{name: "id"}]}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Use `attachment?` for general files and `image?` for image-only columns if you want the schema to be semantically accurate. Functionally, both work for either storage op.
|
|
266
|
+
|
|
267
|
+
## Deleting & Replacing Files
|
|
268
|
+
|
|
269
|
+
Delete a stored file from the vault by its `.path` (verified live — the signed URL returns 404 afterwards):
|
|
270
|
+
|
|
271
|
+
```xs
|
|
272
|
+
storage.delete_file { pathname = $stored_file.path }
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
To **replace** a file on a record: store the new upload, `db.edit`/`db.patch` the column with the new stored object, then `storage.delete_file` the old `.path`. Clearing the column (e.g. `db.patch` setting `file` to `null`) removes the reference but does not delete the vault file — call `delete_file` for that. (`storage.delete_file` lives in the `integrations/utilities` topic alongside `create_file_resource` and `read_file_resource`.)
|
|
276
|
+
|
|
277
|
+
## Frontend Pattern (JavaScript)
|
|
278
|
+
|
|
279
|
+
Always send files via `FormData`. **Never** set `Content-Type` manually — the browser sets `multipart/form-data` with the required boundary automatically.
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
// Single file
|
|
283
|
+
async function uploadFile(file, name) {
|
|
284
|
+
const formData = new FormData();
|
|
285
|
+
formData.append('document', file); // field name must match the XanoScript input name
|
|
286
|
+
formData.append('name', name); // text fields go in the same FormData
|
|
287
|
+
const response = await fetch(`${BASE_URL}/upload`, {
|
|
288
|
+
method: 'POST',
|
|
289
|
+
headers: { Authorization: `Bearer ${token}` }, // NO Content-Type header
|
|
290
|
+
body: formData
|
|
291
|
+
});
|
|
292
|
+
if (!response.ok) throw new Error((await response.json()).message);
|
|
293
|
+
return response.json();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Multiple files — append with a `[]` suffix so a `file[]?` input receives ALL files.
|
|
297
|
+
// Appending repeatedly as 'photos' (no brackets) makes Xano keep only the LAST file.
|
|
298
|
+
async function uploadFiles(files, itemId) {
|
|
299
|
+
const formData = new FormData();
|
|
300
|
+
files.forEach(file => formData.append('photos[]', file)); // note the [] suffix
|
|
301
|
+
formData.append('item_id', itemId);
|
|
302
|
+
const response = await fetch(`${BASE_URL}/upload_many`, {
|
|
303
|
+
method: 'POST',
|
|
304
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
305
|
+
body: formData
|
|
306
|
+
});
|
|
307
|
+
return response.json();
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
```html
|
|
312
|
+
<!-- Any file (documents, images, PDFs) -->
|
|
313
|
+
<input type="file" id="document" accept="image/*,application/pdf">
|
|
314
|
+
<!-- Multiple -->
|
|
315
|
+
<input type="file" id="photos" accept="image/*" multiple>
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## JSON Endpoints vs Multipart Endpoints
|
|
319
|
+
|
|
320
|
+
- An endpoint with **no** file inputs receives a JSON body (`Content-Type: application/json`).
|
|
321
|
+
- An endpoint with **any** file input must be sent as `FormData` (multipart). If you need both a file and text fields in one request, put everything in `FormData` — text fields become form fields, files become file parts. Do not mix a JSON body with a file part.
|
|
322
|
+
- An endpoint's mode is determined by whether it currently has any file inputs. **Adding a file input to an existing JSON-only endpoint and pushing it via the CLI works** — the endpoint switches to multipart automatically on the next request (verified live; you do **not** need to create a separate endpoint).
|
|
323
|
+
|
|
324
|
+
## Common Mistakes
|
|
325
|
+
|
|
326
|
+
❌ **`image?` input — `Missing param: path` at runtime (validator does NOT catch this):**
|
|
327
|
+
```xs
|
|
328
|
+
input { image? photo }
|
|
329
|
+
stack {
|
|
330
|
+
storage.create_image {
|
|
331
|
+
value = $input.photo
|
|
332
|
+
access = "private"
|
|
333
|
+
filename = $input.photo.name
|
|
334
|
+
} as $f
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
The snippet above is fully valid syntax — `xano_validate_xanoscript` passes it — but it fails at runtime because `image?` never populates `$input.photo.path`.
|
|
338
|
+
|
|
339
|
+
✅ **`file?` input populates `.path`:**
|
|
340
|
+
```xs
|
|
341
|
+
input { file? photo }
|
|
342
|
+
stack {
|
|
343
|
+
storage.create_attachment {
|
|
344
|
+
value = $input.photo
|
|
345
|
+
access = "private"
|
|
346
|
+
filename = $input.photo.name
|
|
347
|
+
} as $f
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
❌ **Touching `.tmp_name` / hand-setting `.path` (hallucinated input properties — AI anti-pattern).** This does **not** help: with an `image?` input the `Missing param: path` error fires at the input layer before the stack runs, so the `|set` never executes (verified live).
|
|
352
|
+
```xs
|
|
353
|
+
input { image? photo }
|
|
354
|
+
stack {
|
|
355
|
+
var $patched {
|
|
356
|
+
value = $input.photo|set:"path":$input.photo.tmp_name
|
|
357
|
+
}
|
|
358
|
+
storage.create_attachment {
|
|
359
|
+
value = $patched
|
|
360
|
+
access = "private"
|
|
361
|
+
filename = $patched.name
|
|
362
|
+
} as $f
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
✅ **Just use `file?`** — Xano sets `.path` for you before the stack runs.
|
|
367
|
+
|
|
368
|
+
❌ **`storage.create_image` for a PDF — `Invalid file extension.` (HTTP 500):**
|
|
369
|
+
```xs
|
|
370
|
+
storage.create_image {
|
|
371
|
+
value = $input.document
|
|
372
|
+
access = "private"
|
|
373
|
+
filename = $input.document.name
|
|
374
|
+
} as $f
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
✅ **`storage.create_attachment` accepts any type:**
|
|
378
|
+
```xs
|
|
379
|
+
storage.create_attachment {
|
|
380
|
+
value = $input.document
|
|
381
|
+
access = "private"
|
|
382
|
+
filename = $input.document.name
|
|
383
|
+
} as $f
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
❌ **Omitting `access` or `filename`** — `storage.create_attachment { value = $input.photo } as $f` fails validation with `Missing required argument 'access'`. Always pass all three.
|
|
387
|
+
|
|
388
|
+
❌ **Comma-separated or commented op args** — `storage.create_attachment { value = ..., filename = ... }` and a comment inside the `{ }` are both parse errors. One argument per line, comments on their own line outside the block.
|
|
389
|
+
|
|
390
|
+
## Error Reference
|
|
391
|
+
|
|
392
|
+
| Error | Status | Cause | Fix |
|
|
393
|
+
|-------|--------|-------|-----|
|
|
394
|
+
| `Missing param: path` (`ERROR_CODE_INPUT_ERROR`, `payload.param` ends in `.path`) | 400 | Input declared `image?`/`video?`/`audio?`/`attachment?` — Xano doesn't set `.path` on the raw upload object | Change input type to `file?` |
|
|
395
|
+
| `Invalid file extension.` (`ERROR_FATAL`) | 500 | `storage.create_image` with a non-image (PDF, HEIC, …) | Use `storage.create_attachment` |
|
|
396
|
+
| `Missing required argument 'access'` (validation, at push time) | — | A `storage.create_*` call omitted `access` (or `filename`) | Pass `value`, `access`, and `filename` |
|
|
397
|
+
| HTTP 403 when fetching a file's `.path` | 403 | The file is `private`; raw paths aren't public | Generate `storage.sign_private_url`, or store the file as `public` |
|
|
398
|
+
| Multiple upload stored only one file | — | Multipart field appended without the `[]` suffix | Append files as `field[]` (e.g. `photos[]`) |
|
|
399
|
+
|
|
400
|
+
## Related Topics
|
|
401
|
+
|
|
402
|
+
| Topic | Use For |
|
|
403
|
+
|-------|---------|
|
|
404
|
+
| `integrations/utilities` | Other `storage.*` ops: `create_file_resource`, `read_file_resource`, `delete_file` |
|
|
405
|
+
| `integrations/cloud-storage` | Uploading to external buckets (AWS S3, Azure, GCP) instead of Xano's vault |
|
|
406
|
+
| `types` | Input block syntax and the full file-type list |
|
|
407
|
+
| `database` | `db.add` and storing the file metadata record |
|
|
408
|
+
| `streaming` | Streaming large files in requests/responses |
|
|
@@ -23,42 +23,70 @@ applyTo: "function/**/*.xs, api/**/*.xs, task/*.xs"
|
|
|
23
23
|
|
|
24
24
|
### File Operations
|
|
25
25
|
|
|
26
|
+
> **⚠️ XanoScript comments use `//`, never `#`.** A `#` inside a `.xs` file is a parse error. Also: comments are not allowed inside an operation's `{ ... }` argument block — keep them on their own line above the op.
|
|
27
|
+
|
|
26
28
|
```xs
|
|
27
|
-
|
|
29
|
+
// create_file_resource turns in-stack data (CSV/JSON/zip output) into a FILE
|
|
30
|
+
// RESOURCE — the same value type a `file?` input produces. It is NOT a stored
|
|
31
|
+
// vault file and has no servable URL/path of its own; to persist or serve it,
|
|
32
|
+
// pass it to storage.create_attachment (see "Storing a generated file" below).
|
|
28
33
|
storage.create_file_resource {
|
|
29
34
|
filename = "report.csv"
|
|
30
35
|
filedata = $csv_content
|
|
31
|
-
} as $
|
|
36
|
+
} as $resource
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
// read_file_resource returns the contents of a file resource (e.g. to parse it).
|
|
34
39
|
storage.read_file_resource {
|
|
35
|
-
value = $input.
|
|
40
|
+
value = $input.upload
|
|
36
41
|
} as $content
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
storage.delete_file { pathname =
|
|
43
|
+
// Delete a stored vault file by its `.path` (the value saved on the DB record).
|
|
44
|
+
storage.delete_file { pathname = $stored_file.path }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Storing a generated file (so it has a URL)
|
|
48
|
+
|
|
49
|
+
A `create_file_resource` value cannot be served directly. Store it via `storage.create_attachment` (or `create_image`), then serve it like any uploaded file — `sign_private_url` for private, or instance URL + `.path` for public:
|
|
50
|
+
|
|
51
|
+
```xs
|
|
52
|
+
storage.create_file_resource {
|
|
53
|
+
filename = "export.csv"
|
|
54
|
+
filedata = $csv_content
|
|
55
|
+
} as $resource
|
|
56
|
+
storage.create_attachment {
|
|
57
|
+
value = $resource
|
|
58
|
+
access = "public"
|
|
59
|
+
filename = "export.csv"
|
|
60
|
+
} as $stored_file
|
|
40
61
|
```
|
|
41
62
|
|
|
63
|
+
Then return `($env.PUBLIC_BASE_URL ~ $stored_file.path)` for public, or `storage.sign_private_url` for private. See `xano_xanoscript_docs({ topic: "file-uploads" })`.
|
|
64
|
+
|
|
42
65
|
### Image/Attachment Handling
|
|
43
66
|
|
|
67
|
+
> **⚠️ Upload inputs must be typed `file?`, not `image?`/`attachment?`.** Only `file` populates `.path` on a multipart upload; the others pass the raw object and `storage.*` fails with `Missing param: path`. Use `storage.create_attachment` (any file type) over `storage.create_image` (image extensions only). Full pattern: `xano_xanoscript_docs({ topic: "file-uploads" })`.
|
|
68
|
+
|
|
44
69
|
```xs
|
|
45
|
-
|
|
70
|
+
// The upload input is declared `file?` so Xano populates `.path` first.
|
|
71
|
+
// input { file? upload }
|
|
72
|
+
|
|
73
|
+
// Create image metadata (images only: JPEG/PNG/GIF/WEBP)
|
|
46
74
|
storage.create_image {
|
|
47
|
-
value = $input.
|
|
75
|
+
value = $input.upload
|
|
48
76
|
access = "public"
|
|
49
|
-
filename =
|
|
77
|
+
filename = $input.upload.name
|
|
50
78
|
} as $image_meta
|
|
51
79
|
|
|
52
|
-
|
|
80
|
+
// Create attachment metadata (any file type — recommended default)
|
|
53
81
|
storage.create_attachment {
|
|
54
|
-
value = $input.
|
|
82
|
+
value = $input.upload
|
|
55
83
|
access = "private"
|
|
56
|
-
filename =
|
|
84
|
+
filename = $input.upload.name
|
|
57
85
|
} as $attachment_meta
|
|
58
86
|
|
|
59
|
-
|
|
87
|
+
// Sign private URL (use the stored .path, never a hand-built path)
|
|
60
88
|
storage.sign_private_url {
|
|
61
|
-
pathname =
|
|
89
|
+
pathname = $attachment_meta.path
|
|
62
90
|
ttl = 300
|
|
63
91
|
} as $signed_url
|
|
64
92
|
```
|
|
@@ -70,12 +98,12 @@ storage.sign_private_url {
|
|
|
70
98
|
### Password Hashing
|
|
71
99
|
|
|
72
100
|
```xs
|
|
73
|
-
|
|
101
|
+
// Password is auto-hashed on insert
|
|
74
102
|
db.add "user" {
|
|
75
103
|
data = { email: $input.email, password: $input.password }
|
|
76
104
|
}
|
|
77
105
|
|
|
78
|
-
|
|
106
|
+
// Verify password
|
|
79
107
|
security.check_password {
|
|
80
108
|
text_password = $input.password
|
|
81
109
|
hash_password = $user.password
|
|
@@ -85,7 +113,7 @@ security.check_password {
|
|
|
85
113
|
### Encryption
|
|
86
114
|
|
|
87
115
|
```xs
|
|
88
|
-
|
|
116
|
+
// Encrypt
|
|
89
117
|
security.encrypt {
|
|
90
118
|
data = $sensitive_data
|
|
91
119
|
algorithm = "aes-256-cbc"
|
|
@@ -93,7 +121,7 @@ security.encrypt {
|
|
|
93
121
|
iv = $env.ENCRYPTION_IV
|
|
94
122
|
} as $encrypted
|
|
95
123
|
|
|
96
|
-
|
|
124
|
+
// Decrypt
|
|
97
125
|
security.decrypt {
|
|
98
126
|
data = $encrypted
|
|
99
127
|
algorithm = "aes-256-cbc"
|
|
@@ -105,7 +133,7 @@ security.decrypt {
|
|
|
105
133
|
### JWT (JWS/JWE)
|
|
106
134
|
|
|
107
135
|
```xs
|
|
108
|
-
|
|
136
|
+
// Sign JWT
|
|
109
137
|
security.jws_encode {
|
|
110
138
|
claims = { user_id: $user.id, role: $user.role }
|
|
111
139
|
key = $env.JWT_SECRET
|
|
@@ -113,7 +141,7 @@ security.jws_encode {
|
|
|
113
141
|
ttl = 3600
|
|
114
142
|
} as $token
|
|
115
143
|
|
|
116
|
-
|
|
144
|
+
// Verify JWT
|
|
117
145
|
security.jws_decode {
|
|
118
146
|
token = $input.token
|
|
119
147
|
key = $env.JWT_SECRET
|
|
@@ -264,9 +292,21 @@ query "export_data" {
|
|
|
264
292
|
storage.create_file_resource {
|
|
265
293
|
filename = "export.zip"
|
|
266
294
|
filedata = $archive
|
|
295
|
+
} as $resource
|
|
296
|
+
|
|
297
|
+
// create_file_resource is not directly servable — store it to get a vault path.
|
|
298
|
+
storage.create_attachment {
|
|
299
|
+
value = $resource
|
|
300
|
+
access = "private"
|
|
301
|
+
filename = "export.zip"
|
|
267
302
|
} as $download
|
|
303
|
+
|
|
304
|
+
storage.sign_private_url {
|
|
305
|
+
pathname = $download.path
|
|
306
|
+
ttl = 600
|
|
307
|
+
} as $download_url
|
|
268
308
|
}
|
|
269
|
-
response = { download_url: $
|
|
309
|
+
response = { download_url: $download_url }
|
|
270
310
|
}
|
|
271
311
|
```
|
|
272
312
|
|
|
@@ -204,14 +204,25 @@ object[] items {
|
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
### File Types
|
|
207
|
+
|
|
208
|
+
> **⚠️ For uploaded files, always use `file`.** Only `file` pre-processes a multipart upload and populates `.path`; `image`/`attachment`/`video`/`audio` pass the raw upload object, so any `storage.*` op fails with `Missing param: path`. The names look like semantic choices but are technical. See `xano_xanoscript_docs({ topic: "file-uploads" })`.
|
|
209
|
+
|
|
207
210
|
```xs
|
|
211
|
+
// ✅ use `file` for ALL uploads — only `file` populates .path
|
|
212
|
+
file generic_file
|
|
213
|
+
// optional upload
|
|
214
|
+
file? document
|
|
215
|
+
// multiple uploads
|
|
216
|
+
file[]? attachments
|
|
217
|
+
|
|
218
|
+
// image/attachment/video/audio exist but DO NOT populate .path on upload —
|
|
219
|
+
// they are mainly useful as table column types for stored file metadata.
|
|
208
220
|
image photo {
|
|
209
221
|
description = "Profile photo"
|
|
210
222
|
}
|
|
211
223
|
attachment document
|
|
212
224
|
video recording
|
|
213
225
|
audio clip
|
|
214
|
-
file generic_file
|
|
215
226
|
```
|
|
216
227
|
|
|
217
228
|
### Geographic Types
|
package/package.json
CHANGED