Skip to content

Attachment API

Alyssa Rosenzweig requested to merge file-upload into master

Should be merged before the corresponding MR on the frontend.

Establishes an attachment API (currently only makes sense for public-facing instances). The regular WebSocket will emit a packet:

{"op": "token", "token": "xxxxxxx"}

That token should be saved for the duration of the session. Multiple token ops may be sent; the latest token sent is always considered the current one (i.e. sending a new token message invalidates all previous tokens).

Then, to upload, the client should make a POST request to /attachment/ at the same origin/port as the websocket, with the query string token parameter equal to the saved token, the Content-Type header set appropriately, and the content body the attachment itself.

POST /attachment/?token=xxxxxxx
Content-Type: image/png

If successful, that endpoint will return a JSON object containing the URL to the uploaded attachment

{"url": "https://wherever.somewhere:7070/attachment/df6cd8f6-083c-44cb-a786-9612a608d06b.png"}

That URL may used by the frontend as it sees fit (for example, sent directly to a buddy as text).

Edited by Alyssa Rosenzweig

Merge request reports