Angular 5+ Resumable Upload Module
- Pause / Resume / Cancel Uploads
- Retries using exponential back-off strategy
- Chunking
- Add ngx-uploadx module as dependency :
npm install ngx-uploadx
- Import UploadxModule in the root module:
//...
import { UploadxModule } from 'ngx-uploadx';
@NgModule({
imports: [
UploadxModule,
// ...
});
// Component code
//...
import { Observable } from 'rxjs/Observable';
import { UploadxOptions, UploadState } from 'ngx-uploadx';
@Component({
selector: 'app-home',
templateUrl: `
<input type="file" [uploadx]="options" (uploadxState)="onUpload($event)">
`
})
export class AppHomeComponent {
options: UploadxOptions = { url: `[URL]`};
onUpload(state: Observable<UploadState>) {
state
.subscribe((item: UploadState) => {
console.log(item);
//...
}
}
<input type="file" [uploadx]="options" [uploadxAction]="control" (uploadxState)="onUpload($event)">
[uploadx]
- [uploadx]: UploadxOptions
- [uploadxAction]: UploadxControlEvent
- (uploadxState): $event <Observable>UploadState
UploadxService
- init(options: UploadxOptions): Observable<UploadState>
Set global module options
// example: ngOnInit() { this.uploadService.init(this.uploadxOptions) .subscribe((item: UploadState) => { console.log(item); //... } }
- handleFileList(fileList: FileList): void
Add files to the upload queue
- control(event: UploadxControlEvent): void
Send event
// example: pause(uploadId: string) { this.uploadService.control({ action: 'pause', uploadId }); }
Name | Defaults? | Description |
---|---|---|
[allowedTypes] | - | Set "accept" attribute |
[autoUpload] | true | Auto upload with global options |
[chunkSize] | 0 | If set to > 0 use chunked upload |
[concurrency] | 2 | Limit the number of concurrent uploads |
[headers] | - | Custom headers |
[method] | "POST" | Upload API initial method |
[token] | - | Auth Bearer token |
[url] | "/upload/" | API URL |
[withCredentials] | false | Use withCredentials xhr option |
Name | Type | Description |
---|---|---|
file | File | FileAPI File |
name | string | file name |
progress | number | progress percentage |
remaining | number | ETA |
response | any | success/error response |
size | number | file size |
speed | number | upload speed bytes/sec |
status | UploadStatus | 'added', 'queue', 'uploading', 'complete', 'error', 'cancelled', 'paused' |
uploadId | string | Unique upload id |
Item custom options, override globals
Name | Type | Description |
---|---|---|
[method] | string | API initial method |
[uploadId] | string | Unique upload id ( ReadOnly ) |
[url] | string | Item URL |
[headers] | { [key: string]: string } | Function | Add custom headers |
[metadata] | any | Add custom data |
Name | Type | Description |
---|---|---|
action | UploadAction | 'uploadAll', 'upload', 'cancel', 'cancelAll', 'pauseAll, 'pause' |
[uploadId] | string | Unique upload id ( ReadOnly ) |
[itemOptions] | UploadItem | Item custom options |
- Start server
npm run server
- Run demo app
npm start
- Navigate to
http://localhost:4200/
Run npm run build
to build the lib.
packaged by ng-packagr
Pull requests are welcome!
- https://developers.google.com/drive/v3/web/resumable-upload
- https://developer.vimeo.com/api/upload/videos#resumable-upload
- https://developer.box.com/v2.0/reference#chunked-upload
The MIT License (see the LICENSE file for the full text)