Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "tus"

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

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.0.20f06b903b6b4e1bee5ba64f3cd70d87b27ece2f84https://github.com/terminusdb/tus.git
d844f62711ebe46101cd0e7db262f81c6dbe18981https://github.com/terminusdb/tus.git
0.0.3f33806d839b8e68c0ac21f931aa508b0040baba61https://github.com/terminusdb/tus.git
0.0.655471d5817aa86b85d315482943c88e5d188f2204https://github.com/terminusdb/tus.git
98a657b1e7aaa0bb58d0a019f6619b8771d7b9e754https://github.com/terminusdb/tus.git
b759f5e6b59b1369a7d56220852c7cc487c0512032https://github.com/terminusdb/tus.git
ce0762e5c165bf37c3359583b84601e176ab38b542https://github.com/terminusdb/tus.git
0.0.8f2212b1b689b98950611bea5ce3a4b362a1d095d12https://github.com/terminusdb/tus.git
0.0.97f991a8ca618638864bfe0b752fcdcd654f97b976https://github.com/terminusdb/tus.git
0.0.100affa99d345550e08acc08c9952e6b10797606c979https://github.com/terminusdb/tus.git
4b73ec1b71d8c7922e4fe40bf98e62e8545f3ce33https://github.com/terminusdb/tus.git
f679b92a4bdd545841672a2ec5e5fdff4f102b442https://github.com/terminusdb/tus.git
0.0.130b352cffc1313c500c651516a8452dcb1d76c6b21https://github.com/terminusdb/tus.git
0.0.14068e00dfd17d5b00bcdb411947b8f254f7afafa01https://github.com/terminusdb/tus.git
99fcefc8230590bc9c4e7bc764c603e7986c2b4418https://github.com/terminusdb/tus.git

TUS in swipl

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:

  • Creation
  • Expiration
  • Checksum
  • Termination

Options

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)]).

Examples

Server

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.

Domains and Authorization in Server

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]).

Client

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.

TODO

The remaining extensions would be desirable:

  • Creation with Upload
  • Concatenation In addition the Creation extension should be checked from the Options call before initiating an upload.

Copyright

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

Contents of pack "tus"

Pack contains 7 files holding a total of 57.7K bytes.