> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deployment/monitoring-and-analytics/vision-events/upload-a-vision-event-image.md).

# Upload a Vision Event Image

## About

This endpoint uploads an image to your workspace for use in [Vision Events](/deployment/monitoring-and-analytics/vision-events.md). The upload is workspace-level and is not tied to any project; the returned `sourceId` can then be referenced in the `images` array when you [create an event](/deployment/monitoring-and-analytics/vision-events/create-a-vision-event.md). Use it to attach the original or output frames a model processed so they are viewable alongside the event.

## HTTP API

Upload an image for use in vision events. This is a workspace-level upload that is not associated with any specific project. The returned `sourceId` can be referenced in the `images` array when creating events.

**Required scope:** `vision-events:write` or `device:update`

{% openapi src="/files/sCDP9kVopV4JkkRK7GDd" path="/vision-events/upload" method="post" %}
[openapi.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-dfdc1702ad3d1a62ad0a661e9609f6bbe2fc8d4c%2Fopenapi.yaml?alt=media)
{% endopenapi %}

### Example Request

```bash
curl -X POST "https://api.roboflow.com/vision-events/upload" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@inspection-photo.jpg" \
  -F "name=inspection-photo.jpg"
```

### Request Parameters

Send as `multipart/form-data`:

* **`file`** (binary, required): The image file to upload. Supported formats: JPEG, PNG, WebP, GIF, TIFF, BMP, HEIC, and AVIF.
* **`name`** (string, optional): A custom name for the image.
* **`metadata`** (JSON string, optional): Custom metadata to attach to the image. Must be a valid JSON object following the same constraints as event custom metadata: max 100 keys, key names must match `[a-zA-Z0-9_ -]+` (max 100 characters), string values max 1000 characters, number and boolean values are also supported.

### Example Response

{% tabs %}
{% tab title="201" %}

```json
{
  "success": true,
  "sourceId": "ve-img-abc123def456",
  "url": "https://storage.roboflow.com/vision-events/images/ve-img-abc123def456.jpg"
}
```

Use the `sourceId` value in the `images[].sourceId` field when [creating a vision event](/deployment/monitoring-and-analytics/vision-events/create-a-vision-event.md#http-api):

```json
{
  "eventId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "eventType": "quality_check",
  "useCaseId": "a1b3c8e1",
  "timestamp": "2024-01-15T10:30:00Z",
  "images": [
    {
      "sourceId": "ve-img-abc123def456",
      "objectDetections": [
        {
          "class": "defect",
          "x": 100,
          "y": 200,
          "width": 50,
          "height": 30,
          "confidence": 0.95
        }
      ]
    }
  ],
  "eventData": {
    "result": "fail"
  }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "No file provided"
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "error": "Insufficient permissions for this resource."
}
```

{% endtab %}
{% endtabs %}

## Python SDK

Upload a local image for use in vision events. The returned `sourceId` can be referenced in the `images` array when creating events.

```python
import roboflow

roboflow.login()

rf = roboflow.Roboflow()
ws = rf.workspace()

# Upload an image
result = ws.upload_vision_event_image("inspection-photo.jpg")
source_id = result["sourceId"]

# You can also provide an optional name and metadata
result = ws.upload_vision_event_image(
    "inspection-photo.jpg",
    name="line-a-check-001",
    metadata={"camera": "cam-1", "shift": "morning"},
)
```

The `sourceId` from the response is used in the `images` array when [creating a vision event](/deployment/monitoring-and-analytics/vision-events/create-a-vision-event.md#python-sdk):

```python
ws.write_vision_event({
    "eventId": "d4e5f6a7-b2c3-4d4e-9f6a-7b8c9d0e1f2a",
    "eventType": "quality_check",
    "useCaseId": "a1b3c8e1",
    "timestamp": "2024-01-15T10:30:00Z",
    "images": [
        {
            "sourceId": source_id,
            "label": "inspection-photo",
            "objectDetections": [
                {"class": "defect", "x": 100, "y": 200, "width": 50, "height": 30, "confidence": 0.95}
            ],
        }
    ],
    "eventData": {"result": "fail"},
})
```

For supported image formats and metadata constraints, see the [REST API reference](#http-api).
