Installations
npm install @sleiss/ngx-awesome-uploader
Developer Guide
Typescript
No
Module System
ESM
Node Version
18.19.1
NPM Version
9.2.0
Score
70.1
Supply Chain
96.9
Quality
78.4
Maintenance
100
Vulnerability
98.9
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (77.16%)
SCSS (10.86%)
HTML (8.94%)
JavaScript (3.04%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
vugar005
Download Statistics
Total Downloads
22,683
Last Day
70
Last Week
209
Last Month
1,060
Last Year
13,103
GitHub Statistics
134 Stars
80 Commits
32 Forks
5 Watchers
21 Branches
10 Contributors
Updated on Dec 23, 2024
Bundle Size
58.06 kB
Minified
10.62 kB
Minified + Gzipped
Package Meta Information
Latest Version
19.0.2
Package Id
@sleiss/ngx-awesome-uploader@19.0.2
Unpacked Size
194.11 kB
Size
39.80 kB
File Count
30
NPM Version
9.2.0
Node Version
18.19.1
Published on
Dec 18, 2024
Total Downloads
Cumulative downloads
Total Downloads
22,683
Last Day
40%
70
Compared to previous day
Last Week
-7.1%
209
Compared to previous week
Last Month
22%
1,060
Compared to previous month
Last Year
163%
13,103
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
2
NGX-AWESOME-UPLOADER
This is an Angular Library for uploading files. It supports: File Upload and Preview (additionally preview images with lightbox), validation, image cropper , drag and drop with multi language support.
Tested on Angular Angular 6+. Supports Server Side Rendering.
Breaking Changes: Check Changes changes if you come from version < 10.
- Install
- Usage
- Configuration
- File Validation
- Built-in validations
- Custom validation
- Cropper
- Custom template
- Multi Language
- Edit Mode
- Bonus
Quick-links
Install
npm install ngx-awesome-uploader --save
Load the module for your app:
1import { FilePickerModule } from 'ngx-awesome-uploader'; 2 3@NgModule({ 4 imports: [ 5 ... 6 FilePickerModule 7 ] 8 }) 9
Usage
In order to make library maximum compatible with apis you need to create and provide custom adapter which implements upload and remove requests. That's because I have no idea how to get file id in upload response json :) . So this libray exposes a FilePickerAdapter abstract class which you can import on your new class file definition:
import { FilePickerAdapter } from 'ngx-awesome-uploader';
After importing it to your custom adapter implementation (EG: CustomAdapter.ts), you must implement those 2 methods which are abstract in the FilePickerAdapter base class which are:
public abstract uploadFile(fileItem: FilePreviewModel): Observable<UploadResponse>;
public abstract removeFile(fileItem: FilePreviewModel): Observable<any>;
You can check DEMO adapter here
Now you can use it in your template
1<ngx-awesome-uploader 2[adapter]="adapter" 3> 4</ngx-awesome-uploader> 5
and in the Component:
1import { HttpClient } from '@angular/common/http'; 2import { DemoFilePickerAdapter } from './demo-file-picker.adapter'; 3import { Component} from '@angular/core'; 4 5@Component({ 6selector: 'demo-file-picker', 7templateUrl: './demo-file-picker.component.html', 8styleUrls: ['./demo-file-picker.component.scss'] 9}) 10 11export class DemoFilePickerComponent { 12adapter = new DemoFilePickerAdapter(this.http); 13constructor(private http: HttpClient) { } 14} 15
Note: As you see you should provide http instance to adapter.
Still in Doubt? Check Minimal Setup Demo
API
1 2/** Whether to enable cropper. Default: disabled */ 3@Input() enableCropper = false; 4 5/** Whether to show default drag and drop template. Default:true */ 6@Input() showeDragDropZone = true; 7 8/** Single or multiple. Default: multi */ 9@Input() uploadType = 'multi'; 10 11/** Max size of selected file in MB. Default: no limit */ 12@Input() fileMaxSize: number; 13 14/** Max count of file in multi-upload. Default: no limit */ 15@Input() fileMaxCount: number; 16 17/** Total Max size limit of all files in MB. Default: no limit */ 18@Input() totalMaxSize: number; 19 20/** Which file types to show on choose file dialog. Default: show all */ 21@Input() accept: string; 22 23/** File extensions filter. Default: any exteion */ 24@Input() fileExtensions: String; 25 26/** Cropper options if cropper enabled. Default: 27dragMode: 'crop', 28aspectRatio: 1, 29autoCrop: true, 30movable: true, 31zoomable: true, 32scalable: true, 33autoCropArea: 0.8 34*/ 35@Input() cropperOptions: Object; 36 37/** Custom Adapter for uploading/removing files. Required */ 38@Input() adapter: FilePickerAdapter; 39 40/** Custom template for dropzone. Optional */ 41@Input() dropzoneTemplate: TemplateRef<any>; 42 43/** Custom Preview Item template. Optional */ 44@Input() itemTemplate: TemplateRef<any>; 45 46/** Whether to show default files preview container. Default: true */ 47@Input() showPreviewContainer = true; 48 49/** Custom validator function. Optional */ 50@Input() customValidator: (file: File) => Observable<boolean>; 51 52/** Custom captions input. Used for multi language support */ 53@Input() captions: UploaderCaptions; 54 55/** Whether to auto upload file on file choose or not. Default: true. You can get files list by accessing component files. */ 56@Input() enableAutoUpload = true; 57 58/** capture paramerter for file input such as user,environment*/ 59@Input() fileInputCapture: string; 60
Output events
1 2/** Emitted when file upload via api success. 3Emitted for every file */ 4@Output() uploadSuccess = new EventEmitter<FilePreviewModel>(); 5 6/** Emitted when file upload via api fails. 7Emitted for every file */ 8@Output() uploadFail = new EventEmitter<HttpErrorResponse>(); 9 10/** Emitted when file is removed via api successfully. 11Emitted for every file */ 12@Output() removeSuccess = new EventEmitter<FilePreviewModel>(); 13 14/** Emitted on file validation fail */ 15@Output() validationError = new EventEmitter<ValidationError>(); 16 17/** Emitted when file is added and passed validations. Not uploaded yet */ 18@Output() fileAdded = new EventEmitter<FilePreviewModel>(); 19 20/** Emitted when file is removed from fileList */ 21@Output() fileRemoved = new EventEmitter<FilePreviewModel>();
File-Validation
Built-in-validations
All validations are emitted through ValidationError event.
To listen to validation errors (in case you provided validations), validationError event is emitted. validationError event implements interface ValidationError and which emits failed file and error type.
Supported validations:
Validation Type | Description | Default |
---|---|---|
fileMaxSize: number | Max size of selected file in MB. | No limit |
fileExtensions: String | Emitted when file does not satisfy provided extension | Any extension |
uploadType: String | Upload type. Values: 'single' and 'multi'. | multi |
totalMaxSize: number | Total Max size of files in MB. If cropper is enabled, the cropped image size is considered. | No limit |
fileMaxCount: number | Limit total files to upload by count | No limit |
Custom-validation
You can also provide your own custom validation along with built-in validations.
You custom validation takes file: File
and returns Observable<boolean>
;
So that means you can provide sync and async validations.
public myCustomValidator(file: File): Observable<boolean> {
if (file.name.includes('panda')) {
return of(true);
}
if (file.size > 50) {
return this.http.get('url').pipe(map((res) => res === 'OK' ));
}
return of(false);
}
and pass to Template:
1<ngx-awesome-uploader 2[customValidator]="myCustomValidator" 3> 4</ngx-awesome-uploader> 5
Check Demo
Cropper
Library uses cropperjs to crop images but you need import it to use it. Example: in index html
1 2<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.4.3/cropper.min.js" async> </script> 3<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.4.3/cropper.css" /> 4
Note: To use cropper, you should set enableCropper to true. Look at API section above.
You can also provide your custom cropper options.
Custom-Template
You can provide custom template to library.
I) To provide custom template for drag and drop zone, use content projection. Example:
1 <ngx-awesome-uploader 2 [adapter]="adapter"> 3 4 <div class="dropzoneTemplate"> 5 <button>Custom</button> 6 </div> 7 8</ngx-awesome-uploader> 9
Note: The wrapper of your custom template must have a class dropzoneTemplate.
II) To use custom file preview template, pass your custom template as below:
1 2<ngx-awesome-uploader #uploader 3 [adapter]="adapter" 4 [itemTemplate]="itemTemplate" 5> 6</ngx-awesome-uploader> 7 8<ng-template #itemTemplate let-fileItem="fileItem" let-uploadProgress="uploadProgress"> 9 10 <p>{{fileItem.file.size}}</p> 11 12 <p>{{fileItem.fileName}}</p> 13 14 <p *ngIf="uploadProgress < 100">{{uploadProgress}}%</p> 15 16 <button (click)="uploader.removeFile(fileItem)">Remove</button> 17 18</ng-template> 19
In custom template uploadProgress and fileItem (which implements FilePrevieModel interface) are exposed .
Multi Language
You can add multi language support for library by providing captions object (which implements UploaderCaptions interface).
Check Demo
Edit Mode
You can show your files without uploading them
@ViewChild('uploader', { static: true }) uploader: FilePickerComponent;
public ngOnInit(): void {
const files = [
{
fileName: 'My File 1 for edit.png'
},
{
fileName: 'My File 2 for edit.xlsx'
}
] as FilePreviewModel[];
this.uploader.setFiles(files);
}
Bonus
You can also check out library router animations
Contribution
You can fork project from github. Pull requests are kindly accepted.
-
Building library: ng build file-picker --prod
-
Running tests: ng test file-picker --browsers=ChromeHeadless
-
Run demo: ng serve

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 9/28 approved changesets -- score normalized to 3
Reason
2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 24 are checked with a SAST tool
Reason
11 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-q9mw-68c2-j6m5
- Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More