From a1d911d02a16f3f3eeea06fd9cb2d81edb204703 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 31 Oct 2024 13:49:05 +0100 Subject: [PATCH] Add/Update HTTP downloads algorithms Fixes #9282, fixes #9212 --- .../processing_algs/qgis/filetools.rst | 124 ++++++++++++++++-- 1 file changed, 115 insertions(+), 9 deletions(-) diff --git a/docs/user_manual/processing_algs/qgis/filetools.rst b/docs/user_manual/processing_algs/qgis/filetools.rst index 10bbd8359ab..4d2ba7c4009 100644 --- a/docs/user_manual/processing_algs/qgis/filetools.rst +++ b/docs/user_manual/processing_algs/qgis/filetools.rst @@ -9,11 +9,9 @@ File tools .. _qgisfiledownloader: -Download file --------------- -Downloads a file specified using a URL (using for instance ``http:`` -or ``file:``). -In other words you can copy/paste a URL and download the file. +Download file via HTTP(S) +---------------------------- +Downloads a URL to the file system with an HTTP(S) GET or POST request. Parameters .......... @@ -34,8 +32,6 @@ Basic parameters - [string] - The URL of the file to download. * - **File destination** - - Optional - ``OUTPUT`` - [string] @@ -44,8 +40,8 @@ Basic parameters One of: .. include:: ../algs_include.rst - :start-after: **file_output_types_skip** - :end-before: **end_file_output_types_skip** + :start-after: **file_output_types** + :end-before: **end_file_output_types** Advanced parameters ^^^^^^^^^^^^^^^^^^^ @@ -100,6 +96,116 @@ Python code :end-before: **end_algorithm_code_section** +.. _qgishttprequest: + +HTTP(S) POST/GET request +------------------------ +Performs a HTTP(S) POST/GET request and returns the HTTP status code and the reply data. +If an error occurs then the error code and the message will be returned. +Optionally, the result can be written to a file on disk. +By default the algorithm will warn on errors. Optionally, the algorithm can be set to treat HTTP errors as failures. + +Parameters +.......... + +.. list-table:: + :header-rows: 1 + :widths: 20 20 20 40 + + * - Label + - Name + - Type + - Description + * - **URL or file path** + - ``URL`` + - [string] + - The URL or path of the file to open. + * - **Method** + - ``METHOD`` + - [enumeration] + + Default: 0 + - The HTTP method to use for the request. Options are: + + * 0 --- GET + * 1 --- POST + * - **POST Data** + + Optional + - ``DATA`` + - [string] + + - The data to add in the body if the request is a POST. + * - **Authentication** + + Optional + - ``AUTH_CONFIG`` + - [authconfig] + + Default: No authentication + - An authentication configuration to pass + * - **Consider HTTP errors as failures** + - ``FAIL_ON_ERROR`` + - [boolean] + + Default: False + - If set, the algorithm will fail on encountering a HTTP error. + * - **File destination** + + Optional + - ``OUTPUT`` + - [string] + + Default: ``[Skip Output]`` + - The result can be written to a file instead of being returned as a string. + Specification of the file destination. One of: + + .. include:: ../algs_include.rst + :start-after: **file_output_types_skip** + :end-before: **end_file_output_types_skip** + +Outputs +....... + +.. list-table:: + :header-rows: 1 + :widths: 20 20 20 40 + + * - Label + - Name + - Type + - Description + * - **File destination** + - ``OUTPUT`` + - [file] + - The downloaded file with the returned result + * - **HTTP Status** + - ``STATUS_CODE`` + - [string] + - The HTTP Status + * - **Network error code** + - ``ERROR_CODE`` + - [string] + - The error code When it fails (like as well on 404 HTTP Status etc.) + * - **Network error message** + - ``ERROR_MESSAGE`` + - [string] + - A string containing the error message in case of failure + * - **Result data** + - ``RESULT_DATA`` + - [string] + - A string containing the result data in case of success + +Python code +........... + +**Algorithm ID**: ``native:httprequest`` + +.. include:: ../algs_include.rst + :start-after: **algorithm_code_section** + :end-before: **end_algorithm_code_section** + + .. _qgisopenurl: Open file or URL