moontech-file-upload
Version:
## About Based on ng2-file-upload
87 lines (86 loc) • 2.75 kB
TypeScript
import { HttpHeaders } from '@angular/common/http';
import { FileLikeObject } from './file-like-object.class';
import { Observable } from 'rxjs/Observable';
export declare type ParsedResponseHeaders = {
[headerFieldName: string]: string;
};
export declare type FilterFunction = {
name: string;
fn: (item?: FileLikeObject, options?: UploadOptions) => boolean;
};
export declare type FileItemEventResponse = {
item: FileItem;
response: string;
status: number;
headers: ParsedResponseHeaders;
};
export interface UploadOptions {
allowedMimeType?: string[];
allowedFileType?: string[];
autoUpload?: boolean;
filters?: FilterFunction[];
headers?: HttpHeaders;
method?: string;
maxFileSize?: number;
url?: string;
disableMultipart?: boolean;
itemAlias?: string;
additionalParameter?: {
[key: string]: any;
};
parametersBeforeFiles?: boolean;
formatDataFunction?: Function;
formatDataFunctionIsAsync?: boolean;
withCredentials?: boolean;
}
export declare class FileItem {
private _id;
private errorSubject;
private successSubject;
private progressSubject;
private cancelSubject;
private pauseSubject;
private options;
private _xhr;
private _file;
private _notModificableFile;
private slicedFile;
private onSlicedBytesSent;
fileLike: FileLikeObject;
progress: number;
bytesSent: number;
isReady: boolean;
isUploading: boolean;
isUploaded: boolean;
isSuccess: boolean;
isCancel: boolean;
isError: boolean;
isPause: boolean;
constructor(file: File, options: UploadOptions);
onError(): Observable<FileItemEventResponse>;
onSuccess(): Observable<FileItemEventResponse>;
onProgress(): Observable<{}>;
onCancel(): Observable<FileItemEventResponse>;
onPause(): Observable<FileItemEventResponse>;
getId(): string;
cancel(): void;
pause(): void;
upload(): void;
validateFile(): boolean;
setOptions(options: UploadOptions): void;
private _mimeTypeFilter(item);
private _fileSizeFilter(item);
private _fileTypeFilter(item);
protected _xhrTransport(): any;
private _onProgress(progress, bytesSent);
protected _parseHeaders(headers: string): ParsedResponseHeaders;
protected _transformResponse(response: string, headers: ParsedResponseHeaders): string;
protected _isSuccessCode(status: number): boolean;
private _setFinalized();
private _onSuccess(response, status, headers);
private _onError(response, status, headers);
private _onCancel(response, status, headers);
private _onPause(response, status, headers);
sliceFile(offset?: number): void;
resetToOriginalFile(): void;
}