Media
Import the following dependency in your file, here you will use these function.
import {
MediaBuilder,
UploadProgressEvent,
UploadCompleteEventData,
UploadErrorEvent
} from 'TruVideoMediaSdk';
Recieve media Response -
The uploadMedia function emits several events during the upload process. These events can be listened to using the NativeEventEmitter from React Native.
onProgress: Emitted to indicate the progress of the upload.
onError: Emitted if there is an error during the upload.
onComplete: Emitted when the upload is complete.
const uploadCallbacks = {
onProgress: (event: UploadProgressEvent) => {
console.log(`ID: ${event.id}, Progress: ${event.progress}%`);
},
onComplete: (event: UploadCompleteEventData) => {
console.log(`ID: ${event.id}, Type: ${event.fileType}`);
},
onError: (event: UploadErrorEvent) => {
console.log(`ID: ${event.id}, Error: ${event.error}`);
},
};
Returned Result With Upload
interface UploadCompleteEventData {
id: string;
createdDate?: string;
remoteId?: string;
uploadedFileURL?: string;
metaData?: string;
tags?: string;
transcriptionURL?: string;
transcriptionLength?: number;
fileType?: string;
}
Upload Media
TruVideoMediaSdk
contains all function required to manage the media module. UploadFile function upload’s a one file at a time i.e. photo or video by taking, URI of the local file path, tag, metaData and it will return promise. Promise that resolves with the response from the server upon successful upload, or rejects with an error if the upload fails.
// this demonstration is using MediaItem which is given by Camera SDK
const uploadMediaItems = async (mediaItems: CameraResult[]) => {
for (const item of mediaItems) {
try {
// use media item or directly provide file path
const mediaBuilder = new MediaBuilder(item.filePath);
// Set Tags
mediaBuilder.setTag("key", "value");
mediaBuilder.setTag("color", "red");
mediaBuilder.setTag("orderNumber", "123");
// Set Metadata
mediaBuilder.setMetaData("key", "value");
mediaBuilder.setMetaData("key1", "1");
mediaBuilder.setMetaData("key2", "[4,5,6]");
// Build Request
var request = await mediaBuilder.build();
// upload with the callback as parameter from above
var res : UploadCompleteEventData = await request.upload(uploadCallbacks);
console.log('Successful: set upload');
console.log('Upload successful:', res);
} catch (error) {
console.error('Upload error:', error);
}
}
};
Search Media
search function will give the list uploaded media with respect to tags, page, pageSize and type
const searchData : UploadCompleteEventData[] =
search(
tags: Map<string, string>,
page: number,
pageSize: number,
type?: MediaType
);
// media type
enum MediaType {
IMAGE = 'Image',
VIDEO = 'Video',
AUDIO = 'AUDIO',
PDF = 'PDF',
}
GetAllRequest
This function will provide all the requests created for Upload Builder
Input Params
var status : UploadRequestStatus | undefined = undefined // for all status
// for specific status
enum UploadRequestStatus {
UPLOADING ="UPLOADING",
IDLE ="IDLE",
ERROR ="ERROR",
PAUSED ="PAUSED",
COMPLETED ="COMPLETED",
CANCELED ="CANCELED",
SYNCHRONIZING ="SYNCHRONIZING",
}
Function Utilisation
const requests : MediaData[] = await getAllFileUploadRequests(status);
GetRequestById
This function will return exact request associated with the id
const request : MediaData = getFileUploadRequestById(id : string);
MediaData
interface MediaData {
id: string;
filePath: string;
fileType: string;
createdAt: string;
updatedAt: string;
tags: string;
metaData: string;
durationMilliseconds: number;
remoteId: string;
remoteURL: string;
transcriptionURL: string;
transcriptionLength: number;
status: string;
progress: number;
}
Last updated
Was this helpful?