Zum Hauptinhalt springen
POST
/
attachment
/
v1
/
upload
Upload an attachment
curl --request POST \
  --url https://api.langdock.com/attachment/v1/upload \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form file='@example-file'
import requests

url = "https://api.langdock.com/attachment/v1/upload"

files = { "file": ("example-file", open("example-file", "rb")) }
headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, files=files, headers=headers)

print(response.text)
const form = new FormData();
form.append('file', '<string>');

const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

options.body = form;

fetch('https://api.langdock.com/attachment/v1/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/attachment/v1/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.langdock.com/attachment/v1/upload"

payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.langdock.com/attachment/v1/upload")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.langdock.com/attachment/v1/upload")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--"

response = http.request(request)
puts response.read_body
{
  "attachmentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "file": {
    "name": "<string>",
    "mimeType": "<string>",
    "sizeInBytes": 123
  }
}
{
"error": "<string>"
}
{
"error": "<string>"
}
{
"message": "<string>"
}
Die Assistants API wird am 16. August eingestellt.Für neue Systeme empfehlen wir die Agents API. Der Upload-Attachment-Endpunkt bleibt gleich, aber du solltest die Agents API Dokumentation referenzieren.Siehe den Migrations-Guide für Details zu den Unterschieden.
Lade Dateien hoch, auf die in Assistenten-Konversationen über ihre Anhangs-IDs verwiesen werden kann.
Um die API zu nutzen, benötigst du einen API-Schlüssel. Du kannst API-Schlüssel in deinen Workspace Einstellungen erstellen.

Anforderungsformat

Dieser Endpunkt akzeptiert multipart/form-data Anfragen mit einem einzelnen Datei-Upload.
ParameterTypErforderlichBeschreibung
fileDateiJaDie Datei, die du hochladen möchtest

Antwortformat

Die API gibt die Informationen zur hochgeladenen Datei zurück:
{
  attachmentId: string;
  file: {
    name: string;
    mimeType: string;
    sizeInBytes: number;
  }
}

Beispiel

const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");

async function uploadAttachment() {
  const form = new FormData();
  form.append("file", fs.createReadStream("example.pdf"));

  const response = await axios.post(
    "https://api.langdock.com/attachment/v1/upload",
    form,
    {
      headers: {
        ...form.getHeaders(),
        Authorization: "Bearer YOUR_API_KEY",
      },
    }
  );

  console.log(response.data);
  // {
  //   attachmentId: "550e8400-e29b-41d4-a716-446655440000",
  //   file: {
  //     name: "example.pdf",
  //     mimeType: "application/pdf",
  //     sizeInBytes: 1234567
  //   }
  // }
}

Fehlerbehandlung

try {
  const response = await axios.post('https://api.langdock.com/attachment/v1/upload', ...);
} catch (error) {
  if (error.response) {
    switch (error.response.status) {
      case 400:
        console.error('Keine Datei angegeben');
        break;
      case 401:
        console.error('Ungültiger API-Schlüssel');
        break;
      case 500:
        console.error('Server-Fehler');
        break;
    }
  }
}
Die hochgeladene Anhangs-ID kann in der Assistant-API verwendet werden, indem du sie in das attachmentIds Array entweder auf Assistenten-Ebene oder Nachrichtenebene aufnimmst.

Migration zur Agents API

Der Upload-Attachment-Endpunkt bleibt in beiden APIs gleich. Für neue Systeme verwende die Agents API Dokumentation:
Langdock blockiert bewusst Browser-basierte Anfragen, um deinen API-Schlüssel zu schützen und die Sicherheit deiner Anwendungen zu gewährleisten. Weitere Informationen findest du in unserem Guide zu Best Practices für API-Schlüssel.

Autorisierungen

Authorization
string
header
erforderlich

API key as Bearer token. Format "Bearer YOUR_API_KEY"

Body

multipart/form-data
file
file
erforderlich

The file to upload

Antwort

Successfully uploaded file

attachmentId
string<uuid>
erforderlich

Unique identifier for the uploaded attachment

file
object
erforderlich