ngx-uploadx
Языки
- TypeScript84,7%
- HTML7,3%
- JavaScript4,5%
- SCSS3,5%
ngx-uploadx
Angular Resumable Upload Module
Key Features
- Pause / Resume / Cancel Uploads
- Retries using exponential back-off strategy
- Chunking
Basic usage
- Add ngx-uploadx module as dependency:
- Add
directive to the component template and provide the required options:uploadx
Please navigate to the src/app sub-folder for more detailed examples.
Server-side setup
API
UploadxOptions
-
Allowed file types (directive only)allowedTypes -
Function used to authorize requests (example)authorize -
Auto start upload when files added. Default value:autoUploadtrue -
Limit upload lifetime. Default value:storeIncompleteHours24 -
Fixed chunk size. If not specified, the optimal size will be automatically adjusted based on the network speed. If set tochunkSize, normal uploading will be used instead of chunked0 -
Dynamic chunk size limitmaxChunkSize -
Set the maximum parallel uploads. Default value:concurrency2 -
URL to create new uploads. Default value:endpoint'/upload' -
Expected server response typeresponseType -
Headers to be appended to each HTTP requestheaders -
Custom metadata to be added to the uploaded filesmetadata -
Allow selecting multiple files. Default value:multiple(directive only)true -
Function called before every request (example)prerequest -
Object to configure retry settings:retryConfigMaximum number of retry attempts. Default value:maxAttempts8Upload not exist and will be restarted. Default value:shouldRestartCodes[404, 410]If one of these codes is received, the request will be repeated with an updated authorization token. Default value:authErrorCodes[401]Retryable 4xx status codes. Default value:shouldRetryCodes[408, 423, 429, 460]Overrides the built-in function that determines whether the operation should be retriedshouldRetryMinimum (initial) retry interval. Default value:minDelay500Maximum retry interval. Default value:maxDelay50_000Delay used between retries for non-error responses with missing range/offset. Default value:onBusyDelay1000Time interval after which unfinished requests must be retriedtimeoutDetermines whether partial chunks should be keptkeepPartial
-
Authorization token as atokenor function returning astringorstringPromise<string> -
Upload API implementation. Built-in:uploaderClass(default),UploaderX. More examplesTus
provideUploadx
Provides configuration options for standalone app (example).
UploadxModule
Adds directives and provide static method for global configuration
💡 No need to import
if you do not use theUploadxModuleoruploadxdirectives in your application.uploadxDrop
Directives
uploadx
File input directive.
selectors: ,
Properties:
-
Set directive options@Input() uploadx: UploadxOptions -
Alias for@Input() options: UploadxOptionspropertyuploadx -
Control the uploads@Input() control: UploadxControlEvent -
Event emitted on upload state change@Output() state: EventEmitter<UploadState>
uploadxDrop
File drop directive.
selector:
💡 Activates the
class on DnD operations..uploadx-drop-active
UploadxService
-
init(options?: UploadxOptions): Observable<UploadState>
Initializes service. Returns Observable that emits a new value on progress or status changes.
-
connect(options?: UploadxOptions): Observable<Uploader[]>
Initializes service. Returns Observable that emits the current queue.
-
disconnect(): void
Terminate all uploads and clears the queue.
-
ngOnDestroy(): void
Called when the service instance is destroyed. Interrupts all uploads and clears the queue and subscriptions.
💡 Normally
is never called becausengOnDestroy()is an application-wide service, and uploading will continue even after the upload component is destroyed.UploadxService -
handleFiles(files: FileList | File | File[], options = {} as UploadxOptions): void
Creates uploaders for files and adds them to the upload queue.
-
control(event: UploadxControlEvent): void
Uploads control.
-
request<T = string>(config: AjaxRequestConfig): Promise<AjaxResponse<T>>
Make HTTP request with
like interface. (example)axios -
state(): UploadState[]
Returns the current state of uploads.
-
queue: Uploader[]
Uploaders array.
-
events: Observable<UploadState>
Uploads state events.
DI tokens
-
: override default configurationUPLOADX_FACTORY_OPTIONS -
: global optionsUPLOADX_OPTIONS -
: override internal ajax libUPLOADX_AJAX
Demo
Checkout the Demo App or run it on your local machine:
- Run script npm start
- Navigate to http://localhost:4200/
Build
Run to build the lib.
packaged by ng-packagr
Bugs and Feedback
For bugs, questions and discussions please use the GitHub Issues.
Contributing
Pull requests are welcome!
To contribute, please read contributing instructions.
License
The MIT License (see the LICENSE file for the full text)