issues: 860625833

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association pull_request body repo type active_lock_reason performed_via_github_app
860625833 MDU6SXNzdWU4NjA2MjU4MzM= 1300 Generating URL for a row inside `render_cell` hook 3243482 open 0     3 2021-04-18T10:14:37Z 2021-05-06T09:13:39Z   CONTRIBUTOR  

Hey,
I am using Datasette to view a database that contains video metadata. It has BLOB columns that contain video thumbnails in JPG format (around 100-500KB per row).

I've registered an output formatter that extends datasette.blob_renderer.render_blob function and serves the column with image/jpeg content type.

from datasette.blob_renderer import render_blob

async def render_jpg(datasette, database, rows, columns, request, table, view_name):
    response = await render_blob(datasette, database, rows, columns, request, table, view_name)
    response.content_type = "image/jpeg"
    response.headers["Content-Disposition"] = f'inline; filename="image.jpg"'
    return response


@hookimpl
def register_output_renderer():
    return {
        "extension": "jpg",
        "render": render_jpg,
        "can_render": lambda: True,
    }

This works well. I can visit http://localhost:8001/mydb/videos/1.jpg?_blob_column=thumbnail and view the image.

I want to display the image directly with an <img> tag (lazy-loaded of course). So, I need a URL, because embedding base64 would increase the page size too much (each image > 100KB).

Datasette generates a link with .blob extension for blob columns. It does this by calling datasette.urls.row_blob

https://github.com/simonw/datasette/blob/7a2ed9f8a119e220b66d67c7b9e07cbab47b1196/datasette/views/table.py#L169-L179

But I have no way of getting the row inside the render_cell hook.

@hookimpl
def render_cell(value, column, table, database, datasette):
    if isinstance(value, bytes) and imghdr.what(None, value):
        # generate url
        return '$renderedLink'

Any pointers?

107914493 issue    

Links from other tables