> For the complete documentation index, see [llms.txt](https://docs.lingoql.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lingoql.com/sub0/apis-abi/practical-examples/wallet-backend-uploads-and-gallery.md).

# Wallet backend: Uploads and gallery

Use this page when the app starts storing user media.

### Best for

Profile galleries, receipts, KYC uploads, and asset metadata.

### What it shows

* Protected uploads
* Upload plus database persistence
* Safe file deletion by storage key

### Use this when

You want file handling to stay inside the same backend definition as the rest of your app.

### Pattern 1. Upload gallery files

Start here when you only need upload storage and response metadata.

```json
{
  "id": "wallet-upload-gallery-01",
  "resource": "upload-gallery",
  "tokenize": {
    "type": "JWT",
    "algorithm": "HS256",
    "encryption_key": "$ENV.JWT_SECRET_KEY"
  },
  "protected": {
    "provide_as": "x-access-token",
    "extract_claims": ["id"]
  },
  "actionables": [
    {
      "id": 1,
      "mode": "UPLOAD",
      "uploads": {
        "max_file_uploads": 2,
        "max_upload_file_size": 20971520,
        "allowed_mimetypes": ["image/png", "image/jpeg", "video/mp4"],
        "upload_folder": "/gallery/$PROTECTED.id"
      },
      "returnables": ["storage_key", "url", "dominant_color", "file_size"]
    }
  ]
}
```

### Pattern 2. Upload files and store gallery rows in PostgreSQL

Use this when uploaded assets must also appear in your database.

```json
{
  "id": "wallet-upload-gallery-postgres-01",
  "resource": "upload-gallery-and-store",
  "tokenize": {
    "type": "JWT",
    "algorithm": "HS256",
    "encryption_key": "$ENV.JWT_SECRET_KEY"
  },
  "protected": {
    "provide_as": "x-access-token",
    "extract_claims": ["id"]
  },
  "actionables": [
    {
      "id": 1,
      "mode": "UPLOAD",
      "uploads": {
        "max_file_uploads": 2,
        "max_upload_file_size": 20971520,
        "allowed_mimetypes": ["image/png", "image/jpeg", "video/mp4"],
        "upload_folder": "/gallery/$PROTECTED.id"
      },
      "returnables": ["storage_key", "url", "dominant_color", "file_size"]
    },
    {
      "id": 2,
      "mode": "QUERY",
      "sql_query": {
        "query": "INSERT INTO gallery (id, user_id, storage_key, url, dominant_color, file_size, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7::timestamptz, $8::timestamptz) RETURNING id, user_id, storage_key, url, dominant_color, file_size",
        "parameters": [
          "$GENERATOR.KSUID",
          "$PROTECTED.id",
          "storage_key",
          "url",
          "dominant_color",
          "file_size",
          "$DATETIME",
          "$DATETIME"
        ],
        "multi": true
      },
      "returnables": ["id", "user_id", "storage_key", "url", "dominant_color", "file_size"],
      "main_returnable": true
    }
  ]
}
```

### Pattern 3. Delete uploaded files

Use this when the client already has the storage keys to remove.

```json
{
  "id": "wallet-delete-gallery-files-01",
  "resource": "delete-gallery-files",
  "tokenize": {
    "type": "JWT",
    "algorithm": "HS256",
    "encryption_key": "$ENV.JWT_SECRET_KEY"
  },
  "protected": {
    "provide_as": "x-access-token",
    "extract_claims": ["id"]
  },
  "actionables": [
    {
      "id": 1,
      "mode": "UPLOAD",
      "uploads": {
        "delete_files": true
      }
    }
  ]
}
```

```json
[
  "uploads/29292/gallery/user_01/avatar.png"
]
```

<details>

<summary>MongoDB variant for gallery persistence</summary>

```json
{
  "id": "wallet-upload-gallery-mongo-01",
  "resource": "upload-gallery-and-store-mongo",
  "tokenize": {
    "type": "JWT",
    "algorithm": "HS256",
    "encryption_key": "$ENV.JWT_SECRET_KEY"
  },
  "protected": {
    "provide_as": "x-access-token",
    "extract_claims": ["id"]
  },
  "actionables": [
    {
      "id": 1,
      "mode": "UPLOAD",
      "uploads": {
        "max_file_uploads": 2,
        "max_upload_file_size": 20971520,
        "allowed_mimetypes": ["image/png", "image/jpeg", "video/mp4"],
        "upload_folder": "/gallery/$PROTECTED.id"
      },
      "returnables": ["storage_key", "url", "dominant_color", "file_size"]
    },
    {
      "id": 2,
      "mode": "QUERY",
      "mongo_query": {
        "collection": "gallery",
        "action": "INSERT",
        "parameters": ["user_id", "storage_key", "url", "dominant_color", "file_size"],
        "with_timestamp": true
      },
      "extract_response_for": [
        {
          "extract": "id",
          "for": "user_id"
        }
      ],
      "returnables": ["id", "user_id", "storage_key", "url", "dominant_color", "file_size"],
      "main_returnable": true
    }
  ]
}
```

</details>

For the upload rules behind these examples, see [File Uploads](/sub0/apis-abi/file-uploads.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lingoql.com/sub0/apis-abi/practical-examples/wallet-backend-uploads-and-gallery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
