Skip to content

API Reference

kexxu_editor_sdk

kexxu_editor_sdk.api.upload_image.upload_image

upload_image(file_path, api_key, ai_object_id, name, image_group_name, image_group_subfolder='', timestamp_ms=0, device_type='user-upload', host='https://api.kexxu.com')

Uploads an image to the Kexxu API using exact multipart boundaries and defaults.

Source code in src/kexxu_editor_sdk/api/upload_image.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def upload_image(
    file_path: str,
    api_key: str,
    ai_object_id: int,
    name: str,
    image_group_name: str,
    image_group_subfolder: str = "",
    timestamp_ms: int = 0,
    device_type: str = "user-upload",
    host: str = "https://api.kexxu.com"
) -> requests.Response:
    """
    Uploads an image to the Kexxu API using exact multipart boundaries and defaults.
    """

    # default timestamp to now
    if timestamp_ms == 0:
        timestamp_ms = int(time.time() * 1000)

    url = f"{host.rstrip('/')}/api/images/upload"
    params = {
        "type": device_type,
        "version": "1",
        "name": name,
        "imageGroupSubFolder": image_group_subfolder,
        "imageGroupName": image_group_name,
        "aiObjectId": str(ai_object_id)
    }

    filename = os.path.basename(file_path)

    with open(file_path, "rb") as f:
        m = MultipartEncoder(
            fields={'file': (filename, f, 'application/octet-stream')},
            boundary="KexxuMultiPartBoundary"
        )

        headers = {
            "Content-Type": m.content_type,
            "apikey": api_key
        }

        response = requests.post(url, params=params, headers=headers, data=m)
        response.raise_for_status()
        return response