Using namedblobfiles in mosaic tiles

I have created a custom persistent tile which I would like to use to upload/display video from. I am not concerned with transcoding the video I just need to be able to upload it in the tile setting page and be able to reference it in the template.

The only way I can see for NamedBlobImage to produce a url is to use plone scales which creates a url via the url parameter.

I see from other topics that the preferred way to do this is to add the content via a richtext file, however I want a custom template for the tile, which references the embedded video. So for the purposes of this use case a richtext tile is not an option.

My custom persistent tile is created like this:

class IMyTile(model.Schema):
    some_image = NamedBlobImage(
        title=_(u"Some Image"))

    some_video = NamedBlobFile(
        title=_(u"Some Video"))

And my view is:

class MyTile(PersistentTile):
    template = ViewPageTemplateFile('templates/')

    def __call__(self):
        return self.template()

In my template I can use @@images to get a url for the image:

<img tal:define="scales view/@@images;
                 image python: scales.scale('some_image', width=1920, height=600, direction='down');"
     tal:attributes="src image/url;
                     width image/width;
                     height image/height;" />

I can't see how I would get to the image directly without using plone scales.

Is there an alternative solution to achieve what I am trying to do?

Some options I had though of were:

  • Uploading the image to the site as its own content object and using a relation field to select it in the tile
  • Seeing if it is possible to pass the video through plone.scales without altering it (probably not possible/advisable)
  • Creating a new view for my tile which can return the data which can be referenced in the template.

check collective.cover's implementation of scaling for tiles; it's probably over-engineered (can be simplified) but it has been working for many years now:

an example of a tile using it:

and its template:

I am not sure what you are trying to do

If you want the 'full image', you can normally use

or are you tryiing to download the file, ... should be something like:

Have you already check, how our deprecated image tile used to work:

Technically, there's custom imagescale support for persistent tiles implemented in so that it saves imagescales close to tile data. The example above uses that. It should work, but it may not have feature parity with the default plone namedfile scales. We simply cannot maintain multiple scale implementations and the current recommendation is to use image content level images also with tiles.

Thanks all for the pointers. I didn't explain very well what I'm trying to do.

I just want to get a url directly to the file that is uploaded in the tile. Something like['some_file'].url but there is no url attribute, only things like data and filename.

The @@images view I think is from Pillow which exposes the data but I'm not sure of the inner workings there.

The solution I have used is to create a @@file browser view which takes the field name as a request variable and then sets the correct content type and outputs the data. So my url will look like http://localhost:8080/Plone/front-page/@@my.package.tiles.some_tile/82ff01713384464792b2efaceb93383c/@@file?field=some_file. In my tile template I can use view/absolute_url to get the tile url, so just a matter of appending @@file?field=some_field

I could add this function to plone.tiles and submit a PR if there was any interest in it?

@iojon' deprecated attachments-tile have example traverser supporting @@download path syntax familiar from plone.namedfile

Generic view could have its place in (as there's also the imagescales-support), but currently the mood seems to be getting rid binaries in tiles by default.