httpupload
— HTTP Upload support (XEP-0363)¶
The XEP-0363 HTTP Upload protocol allows an XMPP client to obtain a PUT and GET URL for storage on the server. It can upload a file (once) using the PUT URL and distribute access to the file via the GET url.
This module does not handle the HTTP part of the interaction. We recommend
to use aiohttp
for this, but you can use any HTTP library which supports
GET, PUT and sending custom headers.
Example use:
client = <your aioxmpp.Client>
http_upload_service = <JID of the HTTP Upload service>
slot = await client.send(aioxmpp.IQ(
type_=aioxmpp.IQType.GET,
to=http_upload_service,
payload=aioxmpp.httpupload.Request(
filename,
size,
content_type,
)
))
# http_put_file is provided by you via an HTTP library
await http_put_file(
slot.put.url,
slot.put.headers,
filename
)
-
class
aioxmpp.httpupload.
Request
(*args, **kwargs)[source]¶ XSO to request an upload slot from the server.
The parameters initialise the attributes below.
-
filename
: str¶ The file name (without path, but possibly with “extension”) of the file to upload. The server MAY use this in the URL.
-
size
: int¶ The size of the file in bytes. This must be accurate and MUST also be used as
Content-Length
header in the PUT request.
-
content_type
: str¶ The MIME type of the file. This MUST be set in the PUT request as
Content-Type
header.
-
-
class
aioxmpp.httpupload.xso.
Slot
[source]¶ XSO representing the an upload slot provided by the server.
-
class
aioxmpp.httpupload.xso.
Get
[source]¶ -
url
: str¶ The URL at which the file can be retrieved after uploading.
-
-
class
aioxmpp.httpupload.xso.
Put
[source]¶ -
url
: str¶ The URL against which the PUT request must be made.
-
headers
: multidict.MultiDict¶ The headers which MUST be used in the PUT request as
multidict.MultiDict
, in addition to theContent-Type
andContent-Length
headers.The headers are already sanitised according to XEP-0363 (see also
HEADER_WHITELIST
).
-