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>"
}
⚠️ Du nutzt unsere API in einem Dedicated Deployment? Ersetze einfach api.langdock.com durch die Base URL deines Deployments: <deployment-url>/api/public
Dies ist die neue Agents API mit nativer Vercel AI SDK Kompatibilität. Der Upload-Attachment-Endpunkt wird von beiden APIs gemeinsam genutzt. Wenn du die veraltete Assistants API verwendest, siehe den Migrations-Guide.
Lade Dateien hoch, auf die in Agent-Konversationen über ihre Anhangs-IDs verwiesen werden kann.
Erfordert einen API-Schlüssel mit dem KNOWLEDGE_FOLDER_API Scope. 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 Agent-API auf zwei Arten verwendet werden:
  1. Pro Nachricht (empfohlen): Füge die Anhangs-UUID in das metadata.attachments Array der Nachricht ein, wenn du die Completions API aufrufst
  2. Auf Agent-Ebene: Füge die Anhangs-UUID in das attachments Array ein, wenn du einen Agenten erstellst oder aktualisierst
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