Downloading¶
When you upload your file you will always get an URL address in the JSON response, but the download endpoints has more to offer than it looks on first view. Let’s explain additional things you can do with the download endpoint.
Features:
- Bytes range support, files could be downloaded partially, videos can be rewinded while streamed
- Big files support
- Content type is sent, so the browser knows the file size and can show the progress bar
- Optional password protection
Common parameters for all endpoints | |
---|---|
name | description |
password | Password to access the file, optionally if the file is password protected |
Regular downloading¶
It’s very simple.
GET /repository/file/d3beb8a9f0some-file-name-there.txt?password=optional-password-there-if-any
Downloading using alias defined in ids_mapping.yaml¶
Aliases are allowing to access files by other names, they can be defined in ./config/ids_mapping.yaml file. It’s very helpful feature when you migrate from other storage application to File Repository.
Example ids_mapping.yaml file:
"oh-my-alias-there": "d3beb8a9f0some-file-name-there.txt"
Example request:
GET /repository/file/oh-my-alias-there
Downloading using hotlink protection¶
Hotlink protection is allowing to generate personalized download urls by combining eg. user’s IP address, some salt, file name and timestamp. Such link cannot be shared with other users.
Note: Hotlink protection endpoint also supports aliasing.
Example request:
GET /stream/531ce1f1d5d242cd5005b3758d3b5435/2219788800/d3beb8a9f0some-file-name-there.txt
The format of the URL is defined in the environment variables:
ANTI_HOTLINK_PROTECTION_ENABLED=true
ANTI_HOTLINK_RESTRICT_REGULAR_URLS=false
ANTI_HOTLINK_URL=/stream/{accessToken}/{expirationTime}/{fileId}
ANTI_HOTLINK_CRYPTO=md5
ANTI_HOTLINK_SECRET_METHOD="\$http_x_expiration_time\$http_test_header MY-AWESOME-SUFFIX"
It means you can change it, so the URL will be different. {expirationTime} is optional, but very helpful.
Short explanation:
The {accessToken} is generated by hashing with eg. md5 the filled-up ANTI_HOTLINK_SECRET_METHOD.
Example: Given ANTI_HOTLINK_SECRET_METHOD is “$http_x_expiration_time$http_test_header MY-AWESOME-SUFFIX” We send a request with {expirationTime} = 123 and a header Test-Header = HELLO
So, the secret would be “123HELLO MY-AWESOME-SUFFIX”, now we have to hash using selected crypto - md5. md5(23HELLO MY-AWESOME-SUFFIX) = 531ce1f1d5d242cd5005b3758d3b5435
It means that we have URL: /stream/531ce1f1d5d242cd5005b3758d3b5435/123/d3beb8a9f0some-file-name-there.txt