Size restrictions in mat-fileupload-queue

1k Views Asked by At

Is there anyway that i can restrict the size of the file getting uploaded?

I use,

  <div>
   <input id="singleFile" type="file" [fileUploadInputFor]="fileUploadQueue" />
   <mat-file-upload-queue #fileUploadQueue [fileAlias]="'file'"
              [httpUrl]="'http://localhost:5000/fileupload'">
    <mat-file-upload [file]="file" [id]="i" *ngFor="let file of fileUploadQueue.files; let i = index">
    </mat-file-upload>
   </mat-file-upload-queue>
 </div>

I need like, the error has to be thrown after selecting the file.

1

There are 1 best solutions below

1
Fabian Küng On

You can do it but it is a bit hacky, check out this stackblitz. You can access the size of the file once it has been selected via fileUploadQueue.files[n].size.

I have added a function in the component that checks the first uploaded file for its size and added also a simple expression in the template to show how to access the file size.

It obviously needs some improvement but should get your started.