File

packages/eui/packages/components/eui-file-upload/utils/eui-file-upload.utils.ts

Index

Methods

Methods

Public getIconForExtension
getIconForExtension(fileExtension: string)

Return the icon to be used with eui-icon-svg of the given extension or a default file icon

Parameters :
Name Type Optional
fileExtension string No
Returns : string

Icon name as string

Public sendData
sendData(data: any, APIEndPoint: string)

Method that will format data in FormData and send them to backend.

Example :
Call the method and log the response in the console.
Example :
this.euiFileUploadUtilsService.sendData(this.form.value, 'http://localhost:3000/api/fake-api').pipe(
    this.euiFileUploadUtilsService.uploadProgress((progress) => {
        console.log(progress);
    }),
    this.euiFileUploadUtilsService.toResponseBody(),
).subscribe((response) => {
     console.log(response);
});
Parameters :
Name Type Optional Description
data any No

Data to send to backend

APIEndPoint string No

Endpoint URL

Returns : Observable<any>

The backend response.

Public toResponseBody
toResponseBody()
Type parameters :
  • T

Method that will return only the body of the backend response.

Example :
Call the method and log the response in the console.
Example :
this.euiFileUploadUtilsService.sendData(this.form.value, 'http://localhost:3000/api/fake-api').pipe(
    this.euiFileUploadUtilsService.uploadProgress((progress) => {
        console.log(progress);
    }),
    this.euiFileUploadUtilsService.toResponseBody(),
).subscribe((response) => {
     console.log(response);
});
Returns : UnaryFunction<Observable<HttpEvent<T>>, Observable<T>>

The backend response.

Public uploadProgress
uploadProgress(cb: (progress: number) => void)
Type parameters :
  • T

Method that will return the upload progress.

Example :
Call the method and log the progress in the console.
Example :
this.euiFileUploadUtilsService.sendData(this.form.value, 'http://localhost:3000/api/fake-api').pipe(
    this.euiFileUploadUtilsService.uploadProgress((progress) => {
        console.log(progress);
    }),
    this.euiFileUploadUtilsService.toResponseBody(),
).subscribe((response) => {
     console.log(response);
});
Parameters :
Name Type Optional Description
cb function No

A method to execute on each progress step.

Returns : MonoTypeOperatorFunction<HttpEvent<T>>

A number between 0 and 100.

results matching ""

    No results matching ""