npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng5-fileupload

v1.2.9

Published

Angular 5 file upload.

Downloads

14

Readme

Getting started

Install ng5-fileupload via:

npm install --save ng5-fileupload

Once installed, you need to import our main module:

import { FileUploadModule } from 'ng5-fileupload';

After imported the file module, is necessary to increase the module in imports place in the app.module.

import { FileUploadModule } from 'ng5-fileupload';

@NgModule({
    declarations: [ AppComponent, ... ],
    imports: [ FileUploadModule, ... ],
    bootstrap: [ AppComponent ]
})
export class AppModule {
}

Integration

After followed the installation, the next step is integrate the component in your project.

For a basic integration, is just necessary call fielupload in your template file. Follow it:

<fileupload></fileupload>

With this tags, the component will appear on page with available features: Drag n' drop and explorer window to select files.

FileUploadComponent

You can call the component of FileUpload within other file angular component for have access of all methods available in it component. For it, you need call the FileUpload in your angular component:

import { FileUploadComponent } from 'ng5-fileupload';
export class AppComponent implements OnInit {
	@ViewChild(FileUploadComponent)
	private _fileUploadCmp: FileUploadComponent;
	...
}

FileUploadService

With this service, you will control some functionalities of FileUpload component. First is necessary inject this service in your angular component:

{ FileUploadServices } from 'ng5-fileupload';
...
export class AppComponent implements OnInit {
	constructor(
		public filSer: FileUploadService
	) {
		...
	}
}

Extensions

With FileUploadService, you can set allowed extensions. When the request is fired, the component will check configured rules and than, case the files doesn't respect this rules, the component will fire a validation exception. The extensions rules, can be setted like this:

this.filSer.setExtensions(['jpg', 'png', 'pdf']);

Note that you can spend an array with all desired extensions. But note too, that the extensions there not have a point in their beginning. You need spend just the extension abbreviation like the above example.

Max files

You can restrict the number of files that the use can choose:

this.fileSer.setMaxFiles(5);

Therefore, the component will not allow more than 5 files.

Max size

You can specify the general max size. With this, the component will calculate total size of all files added to upload and than, case the result to be more than max size, a validation exception will be fired.

Is necessary to spend the value as KBytes:

this.filSer.setMaxSize(3072);

Max size per file

You can especify the max size per file. The value is the size in KBytes:

this.filSer.setMaxSizePerFile(3072);

Independ of you setted a value with setMaxSize(), the component will to respect both rules.

Validations

Now, we need to show to user, the validation exceptions, right? For this, we will use the method validations(). This method, has some sub-methods:

  • hasErrors(): returns a boolean if there are any validation exception;
  • hasGeneralErrors(): when is not because an especifc file. Example: Max size exception;
  • hasIndividualErrors(): when there are individual erros. Example: invalid extesion;
  • getError(key: string): use to verify if there is an specifc general error;
  • get(key: number): use to access the key of the invalid file. Within this method, there is an other method, getError(key: string) with same purpose of above method;
  • getIndividualValidations(): use to returns all files with individual validation exception.

Show validation messages

<ul *ngIf="filSer.validations().hasErrors()">
	<li *ngIf="filSer.validations().getError("LIMIT_EXCEEDED")">
		The max allowed quantity of files, was exceeded.
	</li>
	<li *ngIf="filSer.validations().getError("LIMIT_SIZE_EXCEEDED")">
		The max size allowed, was exceeded.
	</li>
	<li *ngIf="filSer.validations().getError("FILES_NOT_FOUND")">
		You need to attach files.
	</li>
	<ng-container *ngFor="let item of filSer.validations().getIndividualValidations(); let i = index;">
		<li *ngIf="filSer.validations().get(i).getError("FILE_LIMIT_SIZE_EXCEEDED")">
			The file {{item.name}} exceeded the max file size allowed.
		</li>	
		<li *ngIf="filSer.validations().get(i).getError("FILE_INVALID_EXTENSION")">
			The file {{item.name}} has invalid extension.
		</li>	
	</ng-container>
</ul>