media

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package media provides functionality for managing media records in Langfuse.

This package allows you to upload, retrieve, and manage media files associated with traces and observations. Media files can include images, audio, video, documents, and other file types supported by the Langfuse platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the media API client.

func NewClient

func NewClient(cli *resty.Client) *Client

NewClient creates a new media API client.

func (*Client) Get

func (c *Client) Get(ctx context.Context, mediaID string) (*GetMediaResponse, error)

Get retrieves a specific media record by ID.

Returns the media record metadata including content type, size, upload date, and a download URL with expiry information.

func (*Client) GetUploadURL

func (c *Client) GetUploadURL(ctx context.Context, request *GetUploadURLRequest) (*GetUploadURLResponse, error)

GetUploadURL retrieves a presigned upload URL for uploading media.

This endpoint returns a presigned URL that can be used to upload media files directly to the storage provider. If the media file is already uploaded (based on SHA256 hash), the upload URL will be null.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, mediaID string, request *PatchMediaRequest) error

Patch updates a media record with upload status information.

This endpoint is typically used to report the status of a media upload after using the presigned URL obtained from GetUploadURL.

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, request *UploadFileRequest) (*UploadResponse, error)

UploadFile uploads a media file from the local filesystem.

This method reads the file from the provided path and uploads it using UploadFromBytes. If no content type is specified, it will be auto-detected from the file extension.

func (*Client) UploadFromBytes

func (c *Client) UploadFromBytes(ctx context.Context, request *UploadFromBytesRequest) (*UploadResponse, error)

UploadFromBytes uploads media from byte data.

This method handles the complete upload flow: getting a presigned URL, uploading the data, and updating the media record with upload status.

type ContentType

type ContentType string

ContentType represents supported MIME types for media records.

const (
	ContentTypeImagePNG               ContentType = "image/png"
	ContentTypeImageJPEG              ContentType = "image/jpeg"
	ContentTypeImageJPG               ContentType = "image/jpg"
	ContentTypeImageWebP              ContentType = "image/webp"
	ContentTypeImageGIF               ContentType = "image/gif"
	ContentTypeImageSVGXML            ContentType = "image/svg+xml"
	ContentTypeImageTIFF              ContentType = "image/tiff"
	ContentTypeImageBMP               ContentType = "image/bmp"
	ContentTypeAudioMPEG              ContentType = "audio/mpeg"
	ContentTypeAudioMP3               ContentType = "audio/mp3"
	ContentTypeAudioWAV               ContentType = "audio/wav"
	ContentTypeAudioOGG               ContentType = "audio/ogg"
	ContentTypeAudioOGA               ContentType = "audio/oga"
	ContentTypeAudioAAC               ContentType = "audio/aac"
	ContentTypeAudioMP4               ContentType = "audio/mp4"
	ContentTypeAudioFLAC              ContentType = "audio/flac"
	ContentTypeVideoMP4               ContentType = "video/mp4"
	ContentTypeVideoWebM              ContentType = "video/webm"
	ContentTypeTextPlain              ContentType = "text/plain"
	ContentTypeTextHTML               ContentType = "text/html"
	ContentTypeTextCSS                ContentType = "text/css"
	ContentTypeTextCSV                ContentType = "text/csv"
	ContentTypeApplicationPDF         ContentType = "application/pdf"
	ContentTypeApplicationMSWord      ContentType = "application/msword"
	ContentTypeApplicationMSExcel     ContentType = "application/vnd.ms-excel"
	ContentTypeApplicationZIP         ContentType = "application/zip"
	ContentTypeApplicationJSON        ContentType = "application/json"
	ContentTypeApplicationXML         ContentType = "application/xml"
	ContentTypeApplicationOctetStream ContentType = "application/octet-stream"
)

type GetMediaResponse

type GetMediaResponse struct {
	MediaID       string    `json:"mediaId"`
	ContentType   string    `json:"contentType"`
	ContentLength int       `json:"contentLength"`
	UploadedAt    time.Time `json:"uploadedAt"`
	URL           string    `json:"url"`
	URLExpiry     string    `json:"urlExpiry"`
}

GetMediaResponse represents the response from getting a media record.

type GetUploadURLRequest

type GetUploadURLRequest struct {
	TraceID       string      `json:"traceId"`
	ObservationID string      `json:"observationId,omitempty"`
	ContentType   ContentType `json:"contentType"`
	ContentLength int         `json:"contentLength"`
	SHA256Hash    string      `json:"sha256Hash"`
	Field         string      `json:"field"`
}

GetUploadURLRequest represents the request to get a presigned upload URL for media.

type GetUploadURLResponse

type GetUploadURLResponse struct {
	UploadURL string `json:"uploadUrl,omitempty"`
	MediaID   string `json:"mediaId"`
}

GetUploadURLResponse represents the response from getting a presigned upload URL.

type PatchMediaRequest

type PatchMediaRequest struct {
	UploadedAt       time.Time `json:"uploadedAt"`
	UploadHTTPStatus int       `json:"uploadHttpStatus"`
	UploadHTTPError  string    `json:"uploadHttpError,omitempty"`
	UploadTimeMs     int       `json:"uploadTimeMs,omitempty"`
}

PatchMediaRequest represents the request to update a media record.

type UploadFileRequest

type UploadFileRequest struct {
	TraceID       string      `json:"traceId"`
	ObservationID string      `json:"observationId,omitempty"`
	ContentType   ContentType `json:"contentType"`
	Field         string      `json:"field"`
	FilePath      string      `json:"-"` // Not serialized to JSON
}

UploadFileRequest represents the request for uploading a media file.

type UploadFromBytesRequest

type UploadFromBytesRequest struct {
	TraceID       string      `json:"traceId"`
	ObservationID string      `json:"observationId,omitempty"`
	ContentType   ContentType `json:"contentType"`
	Field         string      `json:"field"`
	Data          []byte      `json:"-"` // Not serialized to JSON
}

UploadFromBytesRequest represents the request for uploading media from bytes.

type UploadResponse

type UploadResponse struct {
	MediaID string `json:"mediaId"`
}

UploadResponse represents the response from uploading media.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL