Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | TUS file transport protocol in prolog |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 0.0.14 |
SHA1 sum: | 99fcefc8230590bc9c4e7bc764c603e7986c2b44 |
Home page: | https://github.com/terminusdb/tus |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.0.2 | 0f06b903b6b4e1bee5ba64f3cd70d87b27ece2f8 | 4 | https://github.com/terminusdb/tus.git |
d844f62711ebe46101cd0e7db262f81c6dbe1898 | 1 | https://github.com/terminusdb/tus.git | |
0.0.3 | f33806d839b8e68c0ac21f931aa508b0040baba6 | 1 | https://github.com/terminusdb/tus.git |
0.0.6 | 55471d5817aa86b85d315482943c88e5d188f220 | 4 | https://github.com/terminusdb/tus.git |
98a657b1e7aaa0bb58d0a019f6619b8771d7b9e7 | 54 | https://github.com/terminusdb/tus.git | |
b759f5e6b59b1369a7d56220852c7cc487c05120 | 32 | https://github.com/terminusdb/tus.git | |
ce0762e5c165bf37c3359583b84601e176ab38b5 | 42 | https://github.com/terminusdb/tus.git | |
0.0.8 | f2212b1b689b98950611bea5ce3a4b362a1d095d | 12 | https://github.com/terminusdb/tus.git |
0.0.9 | 7f991a8ca618638864bfe0b752fcdcd654f97b97 | 6 | https://github.com/terminusdb/tus.git |
0.0.10 | 0affa99d345550e08acc08c9952e6b10797606c9 | 79 | https://github.com/terminusdb/tus.git |
4b73ec1b71d8c7922e4fe40bf98e62e8545f3ce3 | 3 | https://github.com/terminusdb/tus.git | |
f679b92a4bdd545841672a2ec5e5fdff4f102b44 | 2 | https://github.com/terminusdb/tus.git | |
0.0.13 | 0b352cffc1313c500c651516a8452dcb1d76c6b2 | 1 | https://github.com/terminusdb/tus.git |
0.0.14 | 068e00dfd17d5b00bcdb411947b8f254f7afafa0 | 1 | https://github.com/terminusdb/tus.git |
99fcefc8230590bc9c4e7bc764c603e7986c2b44 | 18 | https://github.com/terminusdb/tus.git |
TUS protocol for resumable file uploads via HTTP in swipl (see: TUS)
This package implements both the server handlers and a simple client.
The package implements the core protocol along with four extensions:
Options for the server can be set with the set_tus_options/1 predicate which has the following options:
tus_storage_path(Path)
: The Path contains the location of the
storage folder to be used for uploads. If not set it will default to a
temporary directory.tus_max_size(Size)
: The Size is the maximum allowable upload
size in bytes. Defaults to 17_179_869_184
bytes.tus_client_chunk_size(Size)
: The Size is the size of chunks to
be uploaded. The default is 16_777_216
bytes.tus_expiry_seconds(Seconds)
: The Seconds is the total number of
seconds before the resource expires. This will allow resources which
are not fully uploaded to be removed.
For instance, to set a larger client chunk size one can call:
:- set_tus_options([tus_client_chunk_size(33_554_432)]).
To use the TUS server with the HTTP library in swipl you can simply
add a tus_dispatch
call to your http_handler from a chosen endpoint
as follows:
:- http_handler(root(files), tus_dispatch, [ methods([options,head,post,patch,delete]), prefix ]).
In order to determine the location of a given resource when passed the
resource URL in other contexts you can use the utility predicate
tus_uri_resource(URI, Resource)
together with
tus_resource_path(Resource, Resource_Path)
. In this way once a
client has uploaded a resource it can be referred to in client-server
communications, and be moved, modified or manipulated by server code.
The server does not manage authorization, but it is possible to use
authorization to provide isolation of user data by providing the
tus_dispatch/2 predicate with options which include
[domain(Domain)]
.
You can use any authorization system you'd like (basic, JWT etc.) to guard access to this domain token and the domain token will be used to ensure isolation.
The following code shows how you might add a handler which carries with it a domain after authorization. There is a more complete example in the tests in prolog/tus.pl.
:- meta_predicate auth_wrapper(2,?). auth_wrapper(Goal,Request) :- authorize(Request, Domain), call(Goal, [domain(Domain)], Request). spawn_auth_server(URL, Port) :- random_between(49152, 65535, Port), http_server(http_dispatch, [port(Port), workers(1)]), http_handler(root(files), auth_wrapper(tus_dispatch), [ methods([options,head,post,patch,delete]), prefix ]), format(atom(URL), 'http://127.0.0.1:~d/files', [Port]).
The client invocation requires only the endpoint of interest and a file and can be invoked thus:
tus_upload(Example, URL, Resource)
The Resource variable gives back a resource handle that the server can use to refer to the resource in subsequent communication.
The remaining extensions would be desirable:
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Pack contains 7 files holding a total of 57.7K bytes.