API Reference¶
aiohttp_tus¶
-
aiohttp_tus.
setup_tus
(app, *, upload_path, upload_url='/uploads', upload_resource_name=None, allow_overwrite_files=False, decorator=None, on_upload_done=None, json_dumps=<function dumps>, json_loads=<function loads>)[source]¶ Setup tus protocol server implementation for aiohttp.web application.
It is a cornerstone of
aiohttp-tus
library and in most cases only thing developers need to know for setting up tus.io server for aiohttp.web application.- Parameters
app (
Application
) –aiohttp.web.Application
instanceupload_path (
Path
) –pathlib.Path
instance to point the directory where to store uploaded files. Please, esnure that given directory is exists before application start and is writeable for current user.It is possible to prepend any
match_info
param from named URL.upload_url (
str
) – tus.io upload URL. Can be plain as/uploads
or named as/users/{username}/uploads
. By default:"/uploads"
upload_resource_name (
Optional
[str
]) – By defaultaiohttp-tus
will provide auto name for the upload resource, as well as for the chunk resource. But sometimes it might be useful to provide exact name, which can lately be used for URL reversing.allow_overwrite_files (
bool
) – When enabled allow to overwrite already uploaded files. This may harm consistency of stored data, cause please use this param with caution. By default:False
decorator (
Optional
[Callable
[[Callable
[[Request
],Awaitable
[StreamResponse
]]],Callable
[[Request
],Awaitable
[StreamResponse
]]]]) – In case of guarding upload views it might be useful to decorate them with given decorator function. By default:None
(which means ANY client will able to upload files)on_upload_done (
Optional
[Callable
[[Request
,Resource
,Path
],Awaitable
[None
]]]) – Coroutine to call after upload is done. Coroutine will receive three arguments:request
,resource
&file_path
. Request is currentaiohttp.web.Request
instance. Resource will contain all data about uploaded resource such as file name, file size (aiohttp_tus.data.Resource
instance). While file path will containpathlib.Path
instance of uploaded file.json_dumps (
Callable
[[Any
],str
]) –To store resource metadata between chunk uploads
aiohttp-tus
using JSON files, stored intoupload_path / ".metadata"
directory.To dump the data builtin Python function used:
json.dumps()
, but you might customize things if interested in usingujson
,orjson
,rapidjson
or other implementation.json_loads (
Callable
[[str
],Any
]) – Similarly tojson_dumps
, but for loading data from JSON metadata files. By default:json.loads()
- Return type
Application
aiohttp_tus.data¶
-
class
aiohttp_tus.data.
Resource
(file_name, file_size, offset, metadata_header, uid=NOTHING)[source]¶ Dataclass to store resource metadata.
Given dataclass used internally in between resource chunk uploads and is passed to
on_upload_done
callback if one is defined ataiohttp_tus.setup_tus()
call.