Search code examples
angulartypescriptfile-type

TypeScript file type check


I have modified code based on this tutorial to display uploaded images in an angular project.

public uploadFile = (files) => {
    if (files.length === 0) {
      return;
    }

    var mimeType = files[0].type;
    if (mimeType.match(/image\/*/) == null) {
      this.message = "Only images are supported.";
      return;
    }

    var reader = new FileReader();
    reader.readAsDataURL(files[0]); 
    reader.onload = (_event) => { 
      this.imgURL = reader.result; 
    }
}

This works fine, the only thing is, I also want to check if the file is a video. Is the correct syntax

mimeType.match(/video\/*/)

?


Solution

  • You are right: https://help.encoding.com/knowledge-base/article/correct-mime-types-for-serving-video-files/

    Below you can fine full mime types

    Flash           .flv    video/x-flv
    MPEG-4          .mp4    video/mp4
    iPhone Segment  .ts     video/MP2T
    3GP Mobile      .3gp    video/3gpp
    QuickTime       .mov    video/quicktime
    A/V Interleave  .avi    video/x-msvideo
    Windows Media   .wmv    video/x-ms-wmv