Skip to content

Upload Chat Attachment

Upload a file attachment for use in chat messages. Supports images, documents, and other file types.

Endpoint

POST /v1/chat/upload/

Authentication

Required: Admin or Store authentication token

Authorization: Token <your_token>

Request Body

The request must be sent as multipart/form-data:

Field Type Required Description
file file Yes The file to upload
session_id string No Optional session ID for organizing files

Supported File Types

  • Images: JPG, JPEG, PNG, GIF, HEIC, HEIF
  • Documents: PDF, DOC, DOCX, XLS, XLSX

Response

Success (200 OK)

{
  "url": "https://s3.amazonaws.com/bucket/chat/session-1/file.jpg",
  "type": "image/jpeg"
}

Response Fields

Field Type Description
url string Public URL of the uploaded file
type string MIME type of the file (auto-detected)

Error Responses

Missing File (400)

{
  "error": "file is required"
}

Unsupported File Type (400)

{
  "error": "Unsupported file type"
}

Unauthorized (401)

{
  "error": "Unauthorized"
}

Example Request

curl -X POST "https://api.luxmart.site/v1/chat/upload/" \
  -H "Authorization: Token your_token" \
  -F "file=@/path/to/image.jpg" \
  -F "session_id=1"

Using JavaScript (FormData)

const formData = new FormData();
formData.append("file", fileInput.files[0]);
formData.append("session_id", "1");

fetch("https://api.luxmart.site/v1/chat/upload/", {
  method: "POST",
  headers: {
    "Authorization": "Token your_token"
  },
  body: formData
})
  .then(response => response.json())
  .then(data => {
    console.log("File URL:", data.url);
    console.log("File Type:", data.type);
  });

Notes

  • Files are uploaded to S3 storage
  • File organization:
  • If session_id is provided: chat/session-{session_id}/
  • If no session_id:
    • For stores: chat/store-{store_id}/
    • For admins: chat/admin-{admin_id}/
    • Otherwise: chat/general/
  • MIME type is auto-detected from file extension
  • The returned URL can be used in the attachment_url field when sending messages
  • File size limits depend on server configuration