ngx-uploader-directive
Version:
Angular File Uploader Directive which provides two directives, which are select and file drag and drop to upload files on server.
124 lines (123 loc) • 4.83 kB
TypeScript
/**
* @license
* The MIT License (MIT)
* Copyright (c) 2015-2018 Jan Kuri jan@bleenco.com
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { EventEmitter } from '@angular/core';
import { ISelectedFile, IUploadOutput, IUploadInput } from '../models/ngx-uploader-directive-models';
import { Observable, Subscription, Subject } from 'rxjs';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
export declare class NgxUploaderDirectiveService {
private httpClient;
private logs?;
static inputEventReferenceNumber: number;
private devEnv;
queue: Array<ISelectedFile>;
MaxNumberOfRequest: number;
subscriptions: Array<{
id: string;
sub: Subscription;
}>;
fileServiceEvents: EventEmitter<IUploadOutput>;
uploadScheduler: Subject<{
files: Array<ISelectedFile>;
event: IUploadInput;
}>;
fileTypes: Array<string>;
maxFileUploads: number;
maxFileSize: number;
requestConcurrency: number;
maxFilesToAddInSingleRequest: number;
httpErrorResponse: HttpErrorResponse;
constructor(requestConcurrency: number, maxFilesToAddInSingleRequest: number, fileTypes: Array<string>, maxFileUploads: number, maxFileSize: number, httpClient: HttpClient, logs?: boolean);
/**
* Handles uploaded files
* @param selectedFiles Selected Files
*/
handleSelectedFiles(selectedFiles: FileList, selectedEventType: 'DROP' | 'SELECT'): void;
/**
* Handles input events upload | remove | cancel
* @param inputEvnets Input events of file upload process
*/
handleInputEvents(inputEvnets: EventEmitter<IUploadInput>): Subscription;
/**
* Check for file type is valid or not
* @param mimeType file mime type
*/
isFileTypeAllowed(mimeType: string): boolean;
/**
* Start file upload
* @param upload object with files and upload input event
*/
startUpload(upload: {
files: Array<ISelectedFile>;
event: IUploadInput;
}): Observable<IUploadOutput>;
/**
* Upload files to server
* @param files Array of files input
* @param event Upload inout event
*/
uploadFilesHttpRequest(files: Array<ISelectedFile>, event: IUploadInput): Observable<IUploadOutput>;
/**
* Http Request to upload file(s).
* @param requestMethod Request method POST | GET
* @param apiUrl Url to send request
* @param body FormData to passwith
*/
httpRequest(requestMethod: string, apiUrl: string, body: FormData, headers?: HttpHeaders): Observable<any>;
/**
* Converting seconds to human readable
* @param sec Seconds
*/
secondsToHuman(sec: number): string;
/**
* Check for max file size is allowed or not
* @param fileSize file size
*/
isFileSizeAllowed(fileSize: number): boolean;
/**
* Generate Randome file id
*/
generateRandomeId(): string;
/**
* Humanize file Bytes
* @param bytes file bytes
*/
humanizeBytes(bytes: number): string;
/**
* Convert selected file to Selected file Interface
* @param file Selected File
* @param fileIndex File index in array
*/
convertToSelectedFile(file: File, fileIndex: number, id: string, selectedEventType: 'DROP' | 'SELECT'): ISelectedFile;
/**
* Make chunks of array.
* @param array Array to make chunks.
* @param chunkSize Chunk size.
*/
chunkArray(array: Array<any>, chunkSize: number): Array<any>;
/**
* Group by an Array.
* @param array Array of objects
* @param key key
*/
groupByArray(array: Array<any>, key: string): any;
}