Class: QgsFileDownloader

A utility class for downloading files.

To use this class, it is necessary to pass the URL and an output file name as arguments to the constructor, the download will start immediately.

The download is asynchronous.

The object will destroy itself when the request completes, errors or is canceled. An optional authentication configuration can be specified.

Note

This class was part of the GUI library from QGIS 2.18.1 until QGIS 3.0

Class Hierarchy

Inheritance diagram of qgis.core.QgsFileDownloader

Base classes

QObject

Methods

cancelDownload

Call to abort the download and delete this object after the cancellation has been processed.

startDownload

Called to start the download

Signals

downloadCanceled

Emitted when the download was canceled by the user.

downloadCompleted

Emitted when the download has completed successfully

downloadError

Emitted when an error makes the download fail

downloadExited

Emitted always when the downloader exits

downloadProgress

Emitted when data are ready to be processed

class qgis.core.QgsFileDownloader[source]

Bases: QObject

__init__(url: QUrl, outputFileName: str | None, authcfg: str | None = '', delayStart: bool = False, httpMethod: Qgis.HttpMethod = Qgis.HttpMethod.Get, data: QByteArray | bytes | bytearray = QByteArray())

QgsFileDownloader

Parameters:
  • url (QUrl) – the download URL

  • outputFileName (Optional[str]) – file name where the downloaded content will be stored

  • authcfg (Optional[str] = '') – optionally apply this authentication configuration

  • delayStart (bool = False) – if True, the download will not be commenced immediately and must be triggered by a later call to startDownload(). This can be useful if connections need to be made to the downloader and there’s a chance the download will emit signals before these connections have been made.

  • httpMethod (Qgis.HttpMethod = Qgis.HttpMethod.Get) – Method for the HTTP request : GET or POST, since QGIS 3.22

  • data (Union[QByteArray, bytes, bytearray] = QByteArray()) – If the request is POST, some data can be added, since QGIS 3.22

cancelDownload(self)[source]

Call to abort the download and delete this object after the cancellation has been processed.

signal downloadCanceled[source]

Emitted when the download was canceled by the user.

See also

cancelDownload()

signal downloadCompleted(url: QUrl)[source]

Emitted when the download has completed successfully

Parameters:

url (QUrl)

signal downloadError(errorMessages: List[str])[source]

Emitted when an error makes the download fail

Parameters:

errorMessages (List[str])

signal downloadExited[source]

Emitted always when the downloader exits

signal downloadProgress(bytesReceived: int, bytesTotal: int)[source]

Emitted when data are ready to be processed

Parameters:
  • bytesReceived (int)

  • bytesTotal (int)

startDownload(self)[source]

Called to start the download