Video sharing allows users to share one or more videos to the target device or app.
When receiving the videos, the target device will save them to Gallery.
When receiving the videos, the target app can conveniently process the videos. For example, a user can share a video with a MeeTime friend.

Import required modules.
import { systemShare } from '@kit.ShareKit';
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
import { common } from '@kit.AbilityKit';
import { fileUri } from '@kit.CoreFileKit';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit'; (Recommended) Generate a video cover image.
// Generate a video cover image.
let uiContext: UIContext = this.getUIContext();
let contextFaker: Context = uiContext.getHostContext() as Context;
let thumbnailPath = contextFaker.filesDir + '/exampleImage.jpg'; // This is only an example. Replace it with the correct file path.
let imageSource: image.ImageSource = image.createImageSource(thumbnailPath);
let imagePacker: image.ImagePacker = image.createImagePacker();
let buffer: ArrayBuffer = await imagePacker.packToData(imageSource, {
// The value of format can only be image/jpeg, image/webp, or image/png.
format: 'image/jpeg',
// Quality of the output image in JPEG encoding. The value ranges from 0 to 100.
// You are advised to compress the image to a reasonable size. An oversized image will fail to be shared.
quality: 30
}); Construct the data to be shared.
// Construct ShareData. You need to configure a valid data record.
let filePath = contextFaker.filesDir + '/exampleVideo.mp4'; // This is only an example. Replace it with the correct file path.
// Obtain the precise UTD type.
let utdTypeId = utd.getUniformDataTypeByFilenameExtension('.mp4', utd.UniformDataType.VIDEO);
let shareData: systemShare.SharedData = new systemShare.SharedData({
utd: utdTypeId,
uri: fileUri.getUriFromPath(filePath),
title: 'Video title', // If this parameter is not passed, the video file name will be displayed.
description: 'Video description', // If this parameter is not passed, the video size will be displayed.
thumbnail: new Uint8Array(buffer) // You are advised to pass a suitable thumbnail for preview. If no thumbnail is passed, the first frame of the video will be used for preview by default.
}); Add a record.
shareData.addRecord({
utd: utdTypeId,
uri: fileUri.getUriFromPath(filePath),
title: 'Video title', // If this parameter is not passed, the video file name will be displayed.
description: 'Video description' // If this parameter is not passed, the video size will be displayed.
}); Start the sharing panel.
// Display the sharing panel.
let controller: systemShare.ShareController = new systemShare.ShareController(shareData);
let context: common.UIAbilityContext = uiContext.getHostContext() as common.UIAbilityContext;
controller.show(context, {
selectionMode: systemShare.SelectionMode.SINGLE,
previewMode: systemShare.SharePreviewMode.DETAIL
}).then(() => {
console.info('ShareController show success.');
}).catch((error: BusinessError) => {
console.error(`ShareController show error. code: ${error.code}, message: ${error.message}`);
}); For details about the complete sample code, please refer to Sample Code - Sharing Videos.