POST
/
attachment
/
v1
/
upload
Upload an attachment
curl --request POST \
  --url https://api.langdock.com/attachment/v1/upload \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: multipart/form-data' \
  --form file=@example-file
{
  "attachmentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "file": {
    "name": "<string>",
    "mimeType": "<string>",
    "sizeInBytes": 123
  }
}
Lade Dateien hoch, auf die in Assistant-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('No file provided');
        break;
      case 401:
        console.error('Invalid API key');
        break;
      case 500:
        console.error('Server error');
        break;
    }
  }
}
Die hochgeladene Anhangs-ID kann in der Assistant-API verwendet werden, indem du in das attachmentIds Array entweder auf Assistant-Ebene oder Nachrichtenebene aufgenommen wird.

Headers

Authorization
string
required

API key as Bearer token. Format "Bearer YOUR_API_KEY"

Body

multipart/form-data
file
file
required

The file to upload

Response

Successfully uploaded file

attachmentId
string<uuid>
required

Unique identifier for the uploaded attachment

file
object
required