class XMPP::HTTPUpload

Overview

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

Defined in:

xmpp/http_upload.cr

Constant Summary

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

Disco feature advertised by upload services.

Constructors

Instance Method Summary

Constructor Detail

def self.new(client : Client, service : String) #

[View source]

Instance Method Detail

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


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]