ionic5 video upload

<ion-item>
          <ion-label>Upload Video Resume</ion-label>
          <ion-input type="file" (change)="onFileChanged($event)" accept="video/*" formControlName="video"></ion-input>
          <video [src]="url" *ngIf="url" height="200" controls></video> <br/>
        </ion-item>
onFileChanged(event: any) {
    if (event.target.files && event.target.files.length > 0) {
      const max_size = 20000000;
      const allowed_types = ['video/mp4', 'video/avi'];
        if (event.target.files[0].size > max_size) {
          console.log("entered in loop")
          this.imageError = 'Maximum size allowed is ' + max_size / 1000 + 'Mb';
          console.log(this.imageError)
          return false;
          console.log("Failed")
        }
        if (!_.includes(allowed_types, event.target.files[0].type)) {
            this.imageError = 'Only Images are allowed ( mp4 | AVI )';
            console.log(this.imageError)
            return false;
        }
        this.files = event.target.files[0];
        let reader = new FileReader();
        reader.readAsDataURL(event.target.files[0]); // read file as data url
        reader.onload = (event) => { // called once readAsDataURL is completed
            this.url = event.target['result'];
            console.log(this.url)
        }
      }
  }

Comments

Popular posts from this blog

how to split array as per fixed length, and ionic two dates differences in min,seconds,hours

How to Add Firebase Analytics to Your NativeScript Mobile App