# Example: Reading a file into memory and logging it
with open("image.png", "rb") as f:
    image_data = f.read()

print(process_image(image_data))
```

<Note>
  When using raw bytes, Opik automatically creates a temporary file for upload
  and cleans it up after the attachment is uploaded. If you don't specify a
  `content_type`, Opik will try to infer it from the `file_name` or default
  to `application/octet-stream`.
</Note>

### Logging images from HTTP responses

A common use case is logging images fetched from external APIs or URLs:

```python wordWrap
import httpx
from opik import opik_context, track, Attachment

@track
def analyze_remote_image(image_url: str):
    # Fetch image from URL
    response = httpx.get(image_url)
    image_bytes = response.content
    content_type = response.headers.get("content-type", "image/jpeg")

    # Log the fetched image as an attachment
    opik_context.update_current_trace(
        attachments=[
            Attachment(
                data=image_bytes,
                file_name="remote_image.jpg",
                content_type=content_type,
            )
        ]
    )

    # Process the image...
    return "Image analyzed!"