Capítulo 233 de 988
When building an app that accepts user video uploads, you might want to validate whether the browser can play the video before uploading it.
const canDecode = async (src: string | Blob) => {
return true;
};
const upload = async (file: File) => {
return 'https://example.com/video.mp4';
};
const handleUpload = async (file: File) => {
const isCompatible = await canDecode(file);
if (!isCompatible) {
// Either notify user or reject the video
alert('Video format not supported.');
return;
}
try {
const url = await upload(file);
console.log('Video uploaded successfully:', url);
} catch (error) {
console.error('Failed to process video:', error);
alert('Failed to upload video');
}
};