Skip to main content

外来文件类型

如果你传递的文件不是支持的格式之一,parseMedia() 将抛出错误。
尽管如此,有时这个错误仍可能包含关于文件类型的有用信息。

🌐 If you pass a file that is not one of the supported formats, parseMedia() will throw an error.
Sometimes this error can contain useful information about the file type nonetheless.

如果你允许用户上传任意文件,并希望只通过一次操作就获取有关该文件的信息,这将非常有用。

🌐 This is useful if you allow users to upload an arbitrary file and want to get information about it with just one pass.

Get information about a video, or get the file type if it's not a video
import {parseMedia, IsAnImageError, IsAPdfError, IsAnUnsupportedFileTypeError} from '@remotion/media-parser'; try { await parseMedia({ src: 'https://example.com/my-video.png', fields: {}, }); } catch (e) { if (e instanceof IsAnImageError) { console.log('The file is an image of format:', e.imageType, 'dimensions:', e.dimensions); } else if (e instanceof IsAPdfError) { console.log('The file is a PDF'); } else if (e instanceof IsAnUnsupportedFileTypeError) { console.log('The file is of an unsupported type'); } }

可用错误

🌐 Available errors

IsAnImageError

如果图片是 pngjpegbmpgifwebp,则会出现错误。

🌐 An error if the image is a png, jpeg, bmp, gif or webp.

  • fileName:文件的名称 - 来自文件名或 Content-Disposition 头部。
  • sizeInBytes:文件的字节大小。
  • mimeType:文件的 MIME 类型。
  • imageType:图片的类型(pngjpegbmpgifwebp)。
  • dimensions:图片的尺寸(widthheight)。

IsAPdfError

如果文件是 PDF,则会出错。

🌐 An error if the file is a PDF.

  • fileName:文件的名称 - 来自文件名或 Content-Disposition 头部。
  • sizeInBytes:文件的字节大小。
  • mimeType:文件的 MIME 类型。

IsAnUnsupportedFileTypeError

如果文件类型是 @remotion/media-parser 无法识别的类型,则会出现错误。

🌐 An error if the file is of a type that @remotion/media-parser does not recognize.

  • fileName:文件的名称 - 来自文件名或 Content-Disposition 头部。
  • sizeInBytes:文件的字节大小。
  • mimeType:文件的 MIME 类型。