# JSProgressMonitor

## Overview

This class is returned to the Servoy client from the FileProvider js\_streamFilesFromServer or js\_streamFilesToServer method\
It is used to monitor the uploads/downloads calling back a Servoy method that can then get the status of the transfer(s)\
It is called repeatedly by a Timer when scheduled with a fixed interval to callback the Servoy method provided.

## Methods Summarized

| Type                                                                                      | Name                                                                                           | Summary                                                                                                                                                                 |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)                                | [cancel()](#cancel)                                                                            | Cancels the transfer process.                                                                                                                                           |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                  | [getCurrentBytesToTransfer()](#getcurrentbytestotransfer)                                      | Returns the number of bytes to transfer for the current file.                                                                                                           |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                  | [getCurrentFileIndex()](#getcurrentfileindex)                                                  | Returns the index of the current file being transferred.                                                                                                                |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                  | [getCurrentTransferredBytes()](#getcurrenttransferredbytes)                                    | Returns the number of bytes already transferred for the current file.                                                                                                   |
| [String](/reference/servoycore/dev-api/js-lib/string.md)                                  | [getCurrentTransferredFileName()](#getcurrenttransferredfilename)                              | Returns the name of the current file being transferred.                                                                                                                 |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                  | [getTotalBytesToTransfer()](#gettotalbytestotransfer)                                          | Returns the total bytes to transfer to or from the server (sum of all the files size)                                                                                   |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                  | [getTotalFilesToTransfer()](#gettotalfilestotransfer)                                          | Returns the total number of files to transfer.                                                                                                                          |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                  | [getTotalTransferredBytes()](#gettotaltransferredbytes)                                        | Returns the total bytes already transferred (for all files)                                                                                                             |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)                                | [isCanceled()](#iscanceled)                                                                    | Returns true if the process was canceled.                                                                                                                               |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)                                | [isFinished()](#isfinished)                                                                    | Returns true if the process is finished.                                                                                                                                |
| [JSProgressMonitor](/reference/servoyextensions/server-plugins/file/jsprogressmonitor.md) | [setProgressCallBack(function, interval)](#setprogresscallback-function-interval)              | Sets a method to be called repeatedly at the given interval (in seconds), the method will receive an instance of this JSProgressMonitor updated with the latest values. |
| [JSProgressMonitor](/reference/servoyextensions/server-plugins/file/jsprogressmonitor.md) | [setProgressCallBack(function, interval, delay)](#setprogresscallback-function-interval-delay) | Sets a method to be called repeatedly at the given interval (in seconds), the method will receive an instance of this JSProgressMonitor updated with the latest values. |

## Methods Detailed

### cancel()

Cancels the transfer process.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

```js
monitor.cancel();
```

### getCurrentBytesToTransfer()

Returns the number of bytes to transfer for the current file.

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### getCurrentFileIndex()

Returns the index of the current file being transferred.

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### getCurrentTransferredBytes()

Returns the number of bytes already transferred for the current file.

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### getCurrentTransferredFileName()

Returns the name of the current file being transferred.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### getTotalBytesToTransfer()

Returns the total bytes to transfer to or from the server (sum of all the files size)

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### getTotalFilesToTransfer()

Returns the total number of files to transfer.

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### getTotalTransferredBytes()

Returns the total bytes already transferred (for all files)

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### isCanceled()

Returns true if the process was canceled.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### isFinished()

Returns true if the process is finished.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

```js
application.output('total transferred: ' + monitor.getTotalTransferredBytes() + ' / ' + monitor.getTotalBytesToTransfer());
application.output('current file: ' + monitor.getCurrentTransferredFileName() + ' ( ' + monitor.getCurrentFileIndex() + ' / ' + monitor.getTotalFilesToTransfer() + ' )');
application.output('current bytes transferred: '+monitor.getCurrentTransferredBytes() + ' / ' + monitor.getCurrentBytesToTransfer());
if (monitor.isCanceled()) {
	application.output('canceled!')
}
if (monitor.isFinished()) {
	application.output('finished!')
}
```

### setProgressCallBack(function, interval)

Sets a method to be called repeatedly at the given interval (in seconds), the method will receive an instance of this JSProgressMonitor updated with the latest values. Can use an optional delay (for testing purpose in developer).

**Parameters**

* [Function](/reference/servoycore/dev-api/js-lib/function.md) **function** the Function to call back at the specified interval
* [Number](/reference/servoycore/dev-api/js-lib/number.md) **interval** the interval (in seconds) to use

**Returns:** [JSProgressMonitor](/reference/servoyextensions/server-plugins/file/jsprogressmonitor.md) this for chaining

**Sample**

```js
// call the progressCallbackFuntion every 2 and a half seconds (with a delay of 200ms in developer):
monitor.setProgressCallBack(progressCallbackFunction, 2.5, (application.isInDeveloper() ? 200 : 0));
```

### setProgressCallBack(function, interval, delay)

Sets a method to be called repeatedly at the given interval (in seconds), the method will receive an instance of this JSProgressMonitor updated with the latest values. Can use an optional delay (for testing purpose in developer).

**Parameters**

* [Function](/reference/servoycore/dev-api/js-lib/function.md) **function** the Function to call back at the specified interval
* [Number](/reference/servoycore/dev-api/js-lib/number.md) **interval** the interval (in seconds) to use
* [Number](/reference/servoycore/dev-api/js-lib/number.md) **delay** adds a delay for testing purpose in Developer

**Returns:** [JSProgressMonitor](/reference/servoyextensions/server-plugins/file/jsprogressmonitor.md) this for chaining

**Sample**

```js
// call the progressCallbackFuntion every 2 and a half seconds (with a delay of 200ms in developer):
monitor.setProgressCallBack(progressCallbackFunction, 2.5, (application.isInDeveloper() ? 200 : 0));
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoyextensions/server-plugins/file/jsprogressmonitor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
