upload: new package implementing client side of XEP-0363 #312

Closed
opened 2 months ago by SamWhited · 1 comments
Owner

A new package should be created, likely called upload (though other names are fine too if we find something we like better) that implements XEP-0363: HTTP File Upload. To start, just the client side of the XEP can be implemented as the server side will be a bit more complex and need some thought.

The suggested API is as follows:

// NS is the namespace used by this package.
const NS = "urn:xmpp:http:upload:0"

// File describes a file to be uploaded.
type File struct {
	Name string
	Size uint64
	Type string
}

func (File) TokenReader() xml.TokenReader {  }
func (File) WriteXML(w xmlstream.TokenWriter) (n int, err error) {  }
func (File) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {  }
func (File) UnmarshalXML(d *Decoder, start StartElement) error {  }

// Slot is a place where a file can be uploaded and later retrieved.
type Slot struct {
	PutURL *url.URL
	GetURL *url.URL

	// Header is the headers that will be set on put requests from the slot.
	// The only valid headers are "Authorization", "Cookie", and "Expires".
	// All other headers will be ignored.
	Header http.Header
}

// Put returns a put request with the appropriate headers that can be used to
// upload a file to the slot.
func (Slot) Put(ctx context.Context, body io.Reader) (*http.Request, error) {  }

func (Slot) TokenReader() xml.TokenReader {  }
func (Slot) WriteXML(w xmlstream.TokenWriter) (n int, err error) {  }
func (Slot) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {  }
func (Slot) UnmarshalXML(d *Decoder, start StartElement) error {  }


// GetSlot requests a URL where we can upload a file.
func GetSlot(ctx context.Context, f File, to jid.JID, s *xmpp.Session) (Slot, error) {  }

// GetSlotIQ is like GetSlot except that it lets you customize the IQ.
// Changing the type of the IQ has no effect.
func GetSlotIQ(ctx context.Context, f File, iq stanza.IQ, s *xmpp.Session) (Slot, error) {  }
A new package should be created, likely called `upload` (though other names are fine too if we find something we like better) that implements [XEP-0363: HTTP File Upload]. To start, just the client side of the XEP can be implemented as the server side will be a bit more complex and need some thought. The suggested API is as follows: ```go // NS is the namespace used by this package. const NS = "urn:xmpp:http:upload:0" // File describes a file to be uploaded. type File struct { Name string Size uint64 Type string } func (File) TokenReader() xml.TokenReader { … } func (File) WriteXML(w xmlstream.TokenWriter) (n int, err error) { … } func (File) MarshalXML(e *xml.Encoder, _ xml.StartElement) error { … } func (File) UnmarshalXML(d *Decoder, start StartElement) error { … } // Slot is a place where a file can be uploaded and later retrieved. type Slot struct { PutURL *url.URL GetURL *url.URL // Header is the headers that will be set on put requests from the slot. // The only valid headers are "Authorization", "Cookie", and "Expires". // All other headers will be ignored. Header http.Header } // Put returns a put request with the appropriate headers that can be used to // upload a file to the slot. func (Slot) Put(ctx context.Context, body io.Reader) (*http.Request, error) { … } func (Slot) TokenReader() xml.TokenReader { … } func (Slot) WriteXML(w xmlstream.TokenWriter) (n int, err error) { … } func (Slot) MarshalXML(e *xml.Encoder, _ xml.StartElement) error { … } func (Slot) UnmarshalXML(d *Decoder, start StartElement) error { … } // GetSlot requests a URL where we can upload a file. func GetSlot(ctx context.Context, f File, to jid.JID, s *xmpp.Session) (Slot, error) { … } // GetSlotIQ is like GetSlot except that it lets you customize the IQ. // Changing the type of the IQ has no effect. func GetSlotIQ(ctx context.Context, f File, iq stanza.IQ, s *xmpp.Session) (Slot, error) { … } ``` [XEP-0363: HTTP File Upload]: https://xmpp.org/extensions/xep-0363.html
SamWhited added this to the v0.21.3 milestone 2 months ago
SamWhited added the
enhancement
label 2 months ago
SamWhited added reference 312_http_upload 2 months ago
Poster
Owner

Fixed by 73f699ea5f

Fixed by 73f699ea5f4b18a8bc7a78d2ab8f74c440c39511
SamWhited closed this issue 1 month ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Reference: mellium/xmpp#312
Loading…
There is no content yet.