Generating images... but with 'state'

37 views
Skip to first unread message

Dan Gravell

unread,
Apr 12, 2013, 7:21:51 AM4/12/13
to lif...@googlegroups.com
Currently I have some code that runs over a bunch of objects. One of these objects has a 'thumbnailUrl' and in my code I have:

<img src={ "/thumbnailProxy?url=" + Helpers.urlEncode(userResponse.thumbnailUrl }/>

The thumbnailProxy is just a LiftRules.DispatchPF matcher that simply proxies the download of the image in the "url" parameter.

How, I want to do something more stateful because I require more information in the userResponse than just the URL. I want the thumbnailProxy to serve the image using the userResponse object above. I could invent some identification for this object with a lookup, but I'd rather 'close' over the userResponse object in the object that serves the <img> src.

Is this possible? Something a bit like the way Javascript function invocation works? (I don't think I want to use JS if I can avoid it here).

Dan


Antonio Salazar Cardozo

unread,
Apr 12, 2013, 11:19:08 AM4/12/13
to lif...@googlegroups.com
I don't have time to go into deep detail, but you can use fmapFunc to map a function to an id, and then instead of appending url= you can append <id>=_ to run the function when the request runs instead of looking up the parameter.
Thanks,
Antonio

Dan Gravell

unread,
Apr 12, 2013, 12:43:26 PM4/12/13
to lif...@googlegroups.com
Thanks for that, I wondered if fmapFunc would be used.

Do you mean the function should be manually looked up and executed by my code? Can the fmapFunc return anything? It's not clear from the API, saying AFuncHolder can return an Any... why wouldn't this be a parameterised type?

Or can the fmapFunc actually return the StreamingResponse (as I'd like it to be) itself?

Dan

Antonio Salazar Cardozo

unread,
Apr 12, 2013, 2:23:56 PM4/12/13
to lif...@googlegroups.com
fmapFuncs themselves are fire and forget in the sense that they aren't relied on to generate a response. However, as they are part of the response rendering pipeline, you can use ResponseShortcutException.shortcutResponse(<LiftResponse instance>) to throw a ResponseShortcutException with a LiftResponse that will be returned instead of anything else Lift would try to do.
Thanks,
Antonio

Dan Gravell

unread,
Apr 15, 2013, 6:57:44 AM4/15/13
to lif...@googlegroups.com
I couldn't get that working - the function is invoked and the exception thrown but the end result in the browser is always a 404.

I forgot to say: this is being invoked in a comet actor. Given that, I suppose another way is to send Base64 encoded <img> tags within the actor, but there are browser limitations with that.

Dan

Antonio Salazar Cardozo

unread,
Apr 15, 2013, 10:31:30 AM4/15/13
to lif...@googlegroups.com
Wait, which part is being invoked in the comet actor? The fmapFunc or the function within it?

Any chance you can simplify the case and post a sample project? The ResponseShortcutException should really work, it goes around most of Lift's processing…
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages