class

XMPP::HTTPUpload

Inherits Reference / Object

HTTPUpload is a high-level client for XEP-0363 - HTTP File Upload.

A server-provided upload service (discovered via disco#info on the service JID) grants a temporary slot: a PUT URL to push the file data to over HTTPS and a GET URL others can later fetch it from.

uploader = XMPP::HTTPUpload.new(client, "upload.example.org") return unless uploader.supported? url = uploader.upload("photo.jpg", File.size(path), "image/jpeg", File.open(path))

See: https://xmpp.org/extensions/xep-0363.html

Constants

NS_HTTP_UPLOAD = "urn:xmpp:http:upload:0"

Disco feature advertised by upload services.

Constructors

new(client : Client, service : String)
Source

Instance methods

request_slot(filename : String, size : UInt64, content_type : String, timeout : Time::Span = 5.seconds) : Stanza::Slot | Nil

request_slot asks the service for a slot for a file of the given size and content type and returns the granted slot (nil on error/timeout).

Source
supported?(timeout : Time::Span = 5.seconds) : Bool

supported? queries the upload service for support and returns true when the urn:xmpp:http:upload:0 feature is advertised.

Source
upload(filename : String, size : UInt64, content_type : String, data : IO, timeout : Time::Span = 5.seconds) : String | Nil

upload requests a slot for the file and PUTs the given data to the granted URL over HTTPS. On a successful upload (HTTP 2xx) the GET URL is returned; nil is returned on failure.

Source
upload(filename : String, size : UInt64, content_type : String, data : String, timeout : Time::Span = 5.seconds) : String | Nil

upload is a convenience overload accepting the payload as a String.

Source