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-tuslibrary 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.Applicationinstanceupload_path (
Path) –pathlib.Pathinstance 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_infoparam from named URL.upload_url (
str) – tus.io upload URL. Can be plain as/uploadsor named as/users/{username}/uploads. By default:"/uploads"upload_resource_name (
Optional[str]) – By defaultaiohttp-tuswill 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:Falsedecorator (
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.Requestinstance. Resource will contain all data about uploaded resource such as file name, file size (aiohttp_tus.data.Resourceinstance). While file path will containpathlib.Pathinstance of uploaded file.json_dumps (
Callable[[Any],str]) –To store resource metadata between chunk uploads
aiohttp-tususing 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,rapidjsonor 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_donecallback if one is defined ataiohttp_tus.setup_tus()call.