File

src/services/fileItem.model.ts

Constructor

constructor(file: File, uploadService: AbstractUploadService, logger: NgxUploadLogger)

Methods

upload
upload(endpoint: UploadEndPoint, options: any)
Returns: void
cancel
cancel()
Returns: void
remove
remove()
Returns: void
ɵonBeforeUploadItem
ɵonBeforeUploadItem()
Returns: void
ɵonProgress
ɵonProgress(progress: number)
Returns: void
ɵonSuccess
ɵonSuccess()
Returns: void
ɵonError
ɵonError()
Returns: void
ɵonCancel
ɵonCancel()
Returns: void

Properties

alias
alias: string
Default value: file
file
file: File
formData
formData: FormData
isCancel
isCancel: boolean
isError
isError: boolean
isReady
isReady: boolean
Default value: true
isSuccess
isSuccess: boolean
progress
progress: number
Default value: 0
sub
sub: Subscription
uploadInProgress
uploadInProgress: boolean
import { AbstractUploadService } from './abstractUpload.service';
import { NgxUploadLogger } from '../utils/logger.model';
import { Subscription } from 'rxjs';
import { UploadEndPoint } from '../utils/configuration.model';

export class FileItem {

    uploadInProgress: boolean;
    isReady = true;
    isSuccess: boolean;
    isCancel: boolean;
    isError: boolean;
    progress = 0;

    formData: FormData = new FormData();

    alias = 'file';

    sub: Subscription;

    constructor(public file: File, private uploadService: AbstractUploadService, protected logger: NgxUploadLogger) {
    }

    upload(endpoint: UploadEndPoint, options?: any) {
        if (endpoint) {
            this.uploadService.uploadFileItem(this, endpoint, options);
        } else {
            this.logger.error('You must define a UploadEndPoint object.');
        }
    }

    cancel() {
        this.logger.debug('upload cancel');
        if (this.uploadInProgress) {
            this.ɵonCancel();
            this.uploadService.cancelFileItem(this);
        }
    }

    remove() {
        this.logger.debug('upload remove');
        this.uploadService.removeFromQueue(this);
    }

    ɵonBeforeUploadItem() {
        this.isReady = true;
        this.uploadInProgress = false;
        this.isSuccess = false;
        this.isCancel = false;
        this.isError = false;
        this.progress = 0;
    }

    ɵonProgress(progress: number) {
        this.isReady = false;
        this.progress = progress;
    }

    ɵonSuccess() {
        this.isReady = false;
        this.uploadInProgress = false;
        this.isSuccess = true;
        this.isCancel = false;
        this.isError = false;
        this.progress = 100;
    }

    ɵonError() {
        this.isReady = false;
        this.uploadInProgress = false;
        this.isSuccess = false;
        this.isCancel = false;
        this.isError = true;
        this.progress = 0;
    }

    ɵonCancel() {
        this.isReady = true;
        this.uploadInProgress = false;
        this.isSuccess = false;
        this.isCancel = true;
        this.isError = false;
        this.progress = 0;
        this.sub.unsubscribe();
    }


}

results matching ""

    No results matching ""