Open In App

Angular PrimeNG FileUpload File Size

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use FileUpload File Size in Angular PrimeNG.

The FileUpload Component is used to take file input from the user. FileUpload File Size can be used to restrict the maximum file size of the uploaded file. It is specified using the maxFileSize property.



Angular PrimeNG FileUpload File Size Properties:

 



Syntax:

<p-fileUpload maxFileSize="size"></p-fileUpload>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

Project Structure

Example 1: Below is a simple example demonstrating the use of the Angular PrimeNG FileUpload File Size. In this example, we are setting maxFileSize to 1B.




<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG FileUpload File Size</h4>
  
<p-fileUpload 
    [maxFileSize]="1" 
    mode="basic" 
    chooseLabel="Upload">
</p-fileUpload>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent { }




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { FileUploadModule } from 'primeng/fileupload';
import { AppComponent } from './app.component';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        ButtonModule,
        HttpClientModule,
        FileUploadModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

Output:

 

Example 2: Below is another example demonstrating the use of the Angular PrimeNG FileUpload File Size. Here the max uploaded file size is set to 1 MB so files less than 1MB in size can be uploaded.




<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG FileUpload File Size</h4>
  
<p-fileUpload
    [maxFileSize]="1000000" 
    [multiple]="true">
</p-fileUpload>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent { }




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { FileUploadModule } from 'primeng/fileupload';
import { AppComponent } from './app.component';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        ButtonModule,
        HttpClientModule,
        FileUploadModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

Output:

 

Reference: https://primefaces.org/primeng/fileupload


Article Tags :