teleshka_media_client 1.0.0
teleshka_media_client: ^1.0.0 copied to clipboard
Dart client for Teleshka Media API. Upload images and videos, generate signed imgproxy URLs for image transformations, and manage media assets.
example/example.dart
import 'package:teleshka_media_client/teleshka_media_client.dart';
void main() async {
// Initialize client
final client = TeleshkaMediaClient(
baseUrl: 'https://media.teleshka.com',
);
// Initialize imgproxy signer
final signer = ImgProxySigner(
keyHex: 'your-imgproxy-key-hex',
saltHex: 'your-imgproxy-salt-hex',
baseUrl: 'https://img.teleshka.com',
);
try {
// Upload a file with progress tracking
final asset = await client.uploadFileComplete(
filePath: '/path/to/photo.jpg',
kind: 'image',
mime: 'image/jpeg',
onProgress: (sent, total) {
final progress = (sent / total * 100).toStringAsFixed(1);
print('Upload progress: $progress%');
},
);
print('Upload complete!');
print('Asset ID: ${asset.id}');
print('State: ${asset.state}');
// Generate optimized image URL
final imageUrl = signer.buildImageUrl(
assetId: asset.id,
width: 800,
height: 600,
format: 'webp',
quality: 85,
);
print('Optimized image URL: $imageUrl');
// List all assets
final assets = await client.listAssets();
print('Total assets: ${assets.total}');
for (final a in assets.assets) {
print('- ${a.filename} (${a.kind}): ${a.state}');
}
} on MediaApiError catch (e) {
print('API Error: ${e.message}');
print('Status code: ${e.statusCode}');
} finally {
client.close();
}
}