Upload Media
This documentation provides guidelines on uploading images and video to server using the TruVideo Media SDK. The SDK offers simple methods to integrate upload functionalities into your application.
Prerequisites
Ensure you have integrated the TruVideo Core SDK into your project and completed with the authentication process
Camera module will provide MediaItem or simply provide filepath to upload (optional)
Step 1 : Create a MediaBuilder object
final builder = MediaBuilder(filePath)
Step 2 : Set tags or metaData mediaBuilder object if required
// Set Tags
builder..setTag("key", "value");
builder..setTag("color", "red");
builder..setTag("orderNumber", "123");
// Set Metadata
builder..setMetaData("key", "value");
builder..setMetaData("key1", "1");
builder..setMetaData("key2", "[4,5,6]");
Step 3 : Build the request with mediaBuilder
await builder.build();
Step 4 : Finally call the upload to push data to server
await builder.upload(
onProgress: (e) => print("Upload Progess: ${e['progress']}%"),
onComplete: (e) => print("Upload Complete: ${e['remoteURL']}"),
onError: (e) => print("Upload Failed: ${e['error']}"),
);
Finalize :
After completing this steps the function should look like
Future<void> performUploadFlow(String filePath) async {
try {
// Create a new MediaBuilder with a test file path
final builder = MediaBuilder(filePath)
..setTag("color", "blue")
..setTag("source", "flutter-sdk")
..setMetaData("uploadedBy", "truvideo");
// Build the media upload request
await builder.build();
final mediaId = builder.getMediaId();
print("Upload media ID is: $mediaId");
// Start the upload with event callbacks
await builder.upload(
onProgress: (e) => print("Upload Progess: ${e['progress']}%"),
onComplete: (e) => print("Upload Complete: ${e['remoteURL']}"),
onError: (e) => print("Upload Failed: ${e['error']}"),
);
// Get info about the same file by ID (replace with actual ID)
// final json = await TruvideoMediaSdk.getFileUploadRequestById(
// builder.getMediaId()!);
// print("Single Upload Request:\n$json");
//
// // Get all saved upload requests
// final all = await TruvideoMediaSdk.getAllFileUploadRequests();
// print("All Upload Requests:\n$all");
} catch (e) {
debugPrint('Upload flow failed: $e');
}
}
Last updated
Was this helpful?