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 ¶
- type Client
- func (c *Client) Get(ctx context.Context, mediaID string) (*GetMediaResponse, error)
- func (c *Client) GetUploadURL(ctx context.Context, request *GetUploadURLRequest) (*GetUploadURLResponse, error)
- func (c *Client) Patch(ctx context.Context, mediaID string, request *PatchMediaRequest) error
- func (c *Client) UploadFile(ctx context.Context, request *UploadFileRequest) (*UploadResponse, error)
- func (c *Client) UploadFromBytes(ctx context.Context, request *UploadFromBytesRequest) (*UploadResponse, error)
- type ContentType
- type GetMediaResponse
- type GetUploadURLRequest
- type GetUploadURLResponse
- type PatchMediaRequest
- type UploadFileRequest
- type UploadFromBytesRequest
- type UploadResponse
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 (*Client) Get ¶
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 ¶
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.