# Ladda upp en lokal bild eller video

Kanonisk URL: https://sosoapi.ai/sv/docs/mcp/upload-asset

`sosoapi_upload_asset`

Ladda upp en lokal bild- eller videofil till en arbetsytas mediebibliotek och registrera den som mediefil. Endast verkliga filer i formaten PNG/JPEG/GIF/WebP/MP4/MOV/WebM/MKV/MPEG upp till 500 MiB från arbetskatalogen, tempmappen, Pictures/Movies/Videos eller SOSOAPI_UPLOAD_ROOTS godtas; punktfiler och punktmappar avvisas. Returnerar mediefilens id och URL för Scheduled Post-medier.

## Profiler och transporter

Profiler: core, full

Transporter: stdio

Välj core eller full för att styra vilka verktyg klienten ser; detta ändrar inte dess behörigheter. Lokal filuppladdning kräver stdio och är inte tillgänglig via HTTP. Ange SOSOAPI_OUTPUT_SCHEMAS=1 för att inkludera utdatascheman vid identifiering. Verktygen returnerar strukturerade resultat med eller utan inställningen.

## Behörigheter och sidoeffekter

Annoteringar hjälper klienter att beskriva ett verktyg. Varje anrop kontrollerar fortfarande användarens autentisering, roll, resursåtkomst och tilldelade funktionsbehörigheter.

```json
{
  "readOnlyHint": false,
  "destructiveHint": false,
  "idempotentHint": true,
  "openWorldHint": true
}
```

`/assets-api/upload/sign` — agent:operate; synchronous_http_response

`/assets-api/upload/complete` — agent:operate; synchronous_http_response

## Indatafält

```json
{
  "type": "object",
  "properties": {
    "workspace_id": {
      "type": "string",
      "format": "uuid"
    },
    "file_path": {
      "type": "string",
      "minLength": 1
    },
    "idempotency_key": {
      "type": "string",
      "minLength": 8,
      "maxLength": 160
    },
    "content_type": {
      "type": "string",
      "minLength": 1
    },
    "title": {
      "type": "string",
      "maxLength": 200
    },
    "description": {
      "type": "string",
      "maxLength": 2000
    },
    "tags": {
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 64
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {}
    }
  },
  "required": [
    "workspace_id",
    "file_path",
    "idempotency_key"
  ]
}
```

## Strukturerat resultat

Detta schema beskriver structuredContent i ett lyckat verktygsresultat. MCP-svaret innehåller även content och kan ange isError när ett anrop misslyckas. För publicering ska du läsa inläggets slutresultat i stället för att tolka en accepterad begäran eller ett textsvar som bekräftelse. Den länkade API-åtgärden förklarar behörigheter och regler för nya försök.

```json
{
  "type": "object",
  "properties": {
    "asset": {
      "type": "object",
      "properties": {
        "id": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string"
            }
          ]
        },
        "workspace_id": {
          "type": "string",
          "format": "uuid"
        },
        "user_id": {
          "type": "string",
          "format": "uuid"
        },
        "asset_type": {
          "type": "string",
          "enum": [
            "text",
            "image",
            "video",
            "audio"
          ]
        },
        "asset_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "preview_url": {
          "description": "Workspace-authorized temporary read URL. Refresh through Asset read/list after preview_expires_at; keep asset_url as persisted media identity.",
          "anyOf": [
            {
              "type": "string",
              "format": "uri"
            },
            {
              "type": "null"
            }
          ]
        },
        "preview_expires_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$"
            },
            {
              "type": "null"
            }
          ]
        },
        "title": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "tags": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "metadata": {
          "anyOf": [
            {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {}
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "source_metadata": {
          "anyOf": [
            {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {}
            },
            {
              "type": "null"
            }
          ]
        },
        "created_at": {
          "type": "string"
        },
        "version": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "id",
        "workspace_id",
        "user_id",
        "asset_type",
        "asset_url",
        "title",
        "description",
        "tags",
        "metadata",
        "created_at"
      ],
      "additionalProperties": false
    },
    "deduped": {
      "type": "boolean"
    }
  },
  "required": [
    "asset",
    "deduped"
  ],
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false
}
```

## Exempel på verktygsanrop

Exemplen använder fiktiva värden som kontrollerats mot schemana. Ersätt ID:n med sådana du får använda, medier med färdiga mediefiler och datum med din bekräftade publiceringstid. Kontrollera kontots behörighet före en skrivning. Denna sida skickar inga API-anrop.

```json
{
  "name": "sosoapi_upload_asset",
  "arguments": {
    "workspace_id": "11111111-1111-4111-8111-111111111111",
    "file_path": "./example.png",
    "idempotency_key": "example-upload-001"
  }
}
```

structuredContent

```json
{
  "asset": {
    "id": 0,
    "workspace_id": "11111111-1111-4111-8111-111111111111",
    "user_id": "11111111-1111-4111-8111-111111111111",
    "asset_type": "text",
    "asset_url": null,
    "title": null,
    "description": null,
    "tags": null,
    "metadata": null,
    "created_at": "example"
  },
  "deduped": false
}
```

## Underliggande API-åtgärder

- [/assets-api/upload/sign](https://sosoapi.ai/sv/docs/api/assets-api-upload-sign)

- [/assets-api/upload/complete](https://sosoapi.ai/sv/docs/api/assets-api-upload-complete)
