micropub media endpoint

From IndieWeb
(Redirected from media endpoint)
Jump to: navigation, search


micropub media endpoint is a Micropub endpoint that exclusively handles file uploads and returns a URL that can be used in a subsequent Micropub request.

Indieweb Examples

  • Aaron Parecki has used a standalone media endpoint since 2016-11-02. The source code is available on GitHub
  • Marty McGuire has used Spano as a Micropub media endpoint on his site since 2017-01-26.
  • Greg V has used a standalone (but part of sweetroll project) media endpoint since 2017-05-11. It supports image processing and S3 storage. It can work on AWS Lambda, though it's on a normal server currently. Source is available on GitHub.

Brainstorming

Discovery via link rel

As Micropub Media Endpoints are often implemented as separate services from a site's "main" Micropub endpoint, it may be useful to allow Micropub clients to discover the media endpoint without needing to query the "main" endpoint at all.

Discovery of a Micropub Media Endpoint could be accomplished like Micropub endpoint discovery, with HTTP Link headers:

Link <https://aaronpk.example/micropub/media>; rel="micropub_media"

Or via HTML Link tag:

<link rel="micropub_media" href="https://aaronpk.example/micropub/media">

Why

Add Media support to a site whose Micropub server is missing it – With the current Media Endpoint discovery algorithm, a micropub client must ask the server whether a media endpoint is available. Micropub/Servers, especially those that create posts for static sites like Jekyll, don't offer media endpoint support. If a user sets up a separate micropub media endpoint, they must configure their "main" micropub server to make it available to clients - a change that could require them to edit the code of the micropub server.

Standalone Media EndpointIndigenous for Android supports uploading files to a media endpoint and copying the URL to the clipboard for use in any context. Separating media endpoint discovery from "main" micropub server discovery would allow micropub clients to manage media without also managing posts on the site.

This is currently implemented by:

And consumed by:

Query the last thing uploaded

A Micropub client should be able to query the Media Endpoint to find the last photo uploaded. This would allow a post interface to appear with the photo pre-populated. This mechanism ends up treating the Media Endpoint as a kind of account-level clipboard, so you could upload a photo from one device then finish the post on another device.

This also gets closer in line with the way the Wordpress uploader works, where images are stored in a media gallery and can be added to posts later. Might need to explore that API to see how they handle querying the list of media.

GET /media-endpoint?q=last
Authorization: Bearer XYZ123

Content-type: application/json

{
  "url": "....."
}

This is currently implemented by:

And consumed by:

  • Quill - queries the media endpoint to find the last uploaded image and pre-populates the photo in the note interface

Response Body

The Micropub spec doesn't define a particular response body when uploading to the media endpoint. It only defines that the response include the created URL in the Location header. However, some tools are easier to work with if they can use the response body instead of having to parse the HTTP headers.

This should also be the same response format used when querying the endpoint to find the last thing uploaded.

If the Accept header prefers text/plain then the response body is just the full URL. Otherwise, a JSON object with a "url" property is returned.

Content-Type: text/plain

https://media.aaronpk.com/filename.jpg
Content-Type: application/json

{
  "url": "https://media.aaronpk.com/filename.jpg"
}

This response currently produced by:

  • Aaron Parecki in his media endpoint on media.aaronpk.com
  • Greg V in sweetroll — instead of "url" there's a JSON structure with a bunch of stuff. For photos: "width", "height", "meta" (metadata extracted by exiv2), "palette" (prominent colors via vibrant), "tiny_preview" (data uri of a tiny WebP preview) and most importantly "source" (links to the actual image in different formats).
  • WordPress Micropub currently returns the parsed metadata about the media file and the alternate sizes currently generated by WordPress on a file upload. It is not specifically reformatted for Micropub at this time.
  • Jonathan LaCour added support for this response in Known in November 2018.

And consumed by:

  • Aaron Parecki - a iOS Workflow that I created to upload to my media endpoint requests a text/plain response and uses the body as the URL, copying it to the clipboard. that was easier than adding a JSON parser to the Workflow.
  • Greg V - sweetroll does rich photo display based on the data generated by the endpoint.

Properties

Where supported, suggesting that an Endpoint accept name, category, and description optionally. This would take the form of a form encoded submission only. I do not want to suggest complicated properties being sent to photos.

The practical reason is that naming photos allows them to be retrieved.

Tagging would allow a query for images that matched a tag for a possible suggested image library search if someone wanted to implement that into a client.

See Also