https://github.com/foliant-docs/foliantcontrib.downloadfile
Download files to use in the project during build.
https://github.com/foliant-docs/foliantcontrib.downloadfile
Last synced: 3 months ago
JSON representation
Download files to use in the project during build.
- Host: GitHub
- URL: https://github.com/foliant-docs/foliantcontrib.downloadfile
- Owner: foliant-docs
- License: mit
- Created: 2021-05-04T10:23:36.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T05:23:28.000Z (about 5 years ago)
- Last Synced: 2026-01-02T17:36:45.952Z (5 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.org/project/foliantcontrib.downloadfile/) [](https://github.com/foliant-docs/foliantcontrib.downloadfile)
# DownloadFile Extension
DownloadFile is a configuration extension for Foliant which downloads external files to use in your project.
It also resolves `!download` YAML tag in the project config and inside XML-tags parameters.
## Installation
```bash
$ pip install foliantcontrib.downloadfile
```
## Usage
To configure DownloadFile add the following section to your foliant.yml file:
```yaml
downloadfile:
fail_fast: true
ignore_ssl_errors: false
queue:
- url: https://example.com/image.png # required
save_to: images/img1.png
login: john
password: qwerty123
- ...
```
`fail_fast`
: When `true`, build will be stopped if any file can't be downloaded. If `false` — unavailable files will be just skipped. Doesn't affect `!download` tag, this one will always break the build on errors. Default: `true`.
`ignore_ssl_errors`
: Switch to `true` to skip SSL certificate check. Default: `false`.
`queue`
: list of files to download. Each file is represented by a dictionary with the following fields:
`url`
: **(requried)** URL to the file which should be downloaded.
`save_to`
: path where the downloaded file should be saved, relative to the project root. If not supplied, file will be saved in the project root with the name from url.
`login`
: login for basic authentication.
`password`
: password for basic authentication.
> **Warning:** don't store plain text passwords in foliant.yml. Use [environment variables](https://foliant-docs.github.io/docs/config/#env).
### `!download` YAML tag
Another way to use DownloadFile is by specifying `!download` YAML tag. This is the quickest and the simplest way, but it comes with a few disadvantages.
Insert the `!download` tag, followed by file URL, in any place in foliant.yml or tag parameters, where file path is expected:
```yaml
preprocessors:
- swaggerdoc:
spec_path: !download https://example.com/swagger.json
mode: widdershins
```
```html
Generated template:
...
```
The downloaded file will be saved in the `.downloadfilecache` directory under a hashed name, and the `!download` tag will be replaced by absolute path to this file.
The cons of this method are that you can't change the saved file path nor other parameters. Also if you reference the same file twice with `!download` tag, it will be downloaded two times.