RESTXQ: Serve images that are not within the web app dir
Wednesday, 6 July 2022 · 6 messages · last reply 7 Jul 2022
EK
Eliot Kimber6 Jul 2022 21:08 #
In my RESTXQ application, I have the XML content in a database but the images referenced from that content is only in a local clone of the git repository from which the XML content is loaded into BaseX.
I would like to serve the images from RESTXQ-generated HTML Pages but I’m not sure how to do that other than to use URLs that include the base64 image data directly.
What I think I need to do is implement a RESTXQ end point that handles image URLs that I know how to convert into image files on the file system but I don’t see how to then return the raw bytes as the return result from the RESTXQ handler function.
I’m trying to avoid copying the images because there’s no other reason to have them in a database or otherwise copy them somewhere else on the file system.
I suppose I could symlink the git directories under the webapp directory but that seems kind of icky too.
Thanks,
E.
_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com<https://www.servicenow.com>
LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow>
ML
Marco Lettere7 Jul 2022 09:28 #
Hi Eliot,
the content in the webap/static folder is served statically at the .../static/myresource path.
Symlinking your folder in there should do the trick. At least up to previous versions of Basex. You could just ad <img
src="/static/myresoiurce"/> in your page...
I think I've read in tne ML about some issues recently with symlinking but I have not investigated in depth the issue ...
Check it out.
M.
Quoted text · Eliot Kimber · 43 lines
On 06/07/22 21:08, Eliot Kimber wrote: > > In my RESTXQ application, I have the XML content in a database but the > images referenced from that content is only in a local clone of the > git repository from which the XML content is loaded into BaseX. > > I would like to serve the images from RESTXQ-generated HTML Pages but > I’m not sure how to do that other than to use URLs that include the > base64 image data directly. > > What I think I need to do is implement a RESTXQ end point that handles > image URLs that I know how to convert into image files on the file > system but I don’t see how to then return the raw bytes as the return > result from the RESTXQ handler function. > > I’m trying to avoid copying the images because there’s no other reason > to have them in a database or otherwise copy them somewhere else on > the file system. > > I suppose I could symlink the git directories under the webapp > directory but that seems kind of icky too. > > Thanks, > > E. > > _____________________________________________ > > *Eliot Kimber* > > Sr Staff Content Engineer > > O: 512 554 9368 > > M: 512 554 9368 > > servicenow.com <https://www.servicenow.com> > > LinkedIn <https://www.linkedin.com/company/servicenow> | Twitter > <https://twitter.com/servicenow> | YouTube > <https://www.youtube.com/user/servicenowinc> | Facebook > <https://www.facebook.com/servicenow> >
CG
Hi Eliot,
Quoted text · Eliot Kimber · 1 line
> I would like to serve the images from RESTXQ-generated HTML Pages but I’m not sure how to do that other than to use URLs that include the base64 image data directly.
The DBA code contains such an endpoint [1]. Memory consumption will be constant: As
file:read-binary is used, the binary data will be streamed directly to the client [2]. The used headers (Cache-Control, Content-Length) are optional and can be arbitrarly adjusted.
Best,
Christian
[1] https://github.com/BaseXdb/basex/blob/da1e55d0214e44c1532f121c282021db50a9aa51/basex-api/src/main/webapp/dba/common.xqm#L21-L41 [2] https://docs.basex.org/wiki/Lazy_ModuleEK
Eliot Kimber7 Jul 2022 14:24 #
Christian,
Thanks for the pointer. I'll see if I can update the docs to more clearly cover this use case.
Cheers,
E.
Quoted text · Christian Grün · 16 lines
From: Christian Grün <christian.gruen at gmail.com> Sent: Thursday, July 7, 2022 4:09 AM To: Eliot Kimber <eliot.kimber at servicenow.com> Cc: basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] RESTXQ: Serve images that are not within the web app dir [External Email] Hi Eliot, > I would like to serve the images from RESTXQ-generated HTML Pages but I’m not sure how to do that other than to use URLs that include the base64 image data directly. The DBA code contains such an endpoint [1]. Memory consumption will be constant: As file:read-binary is used, the binary data will be streamed directly to the client [2]. The used headers (Cache-Control, Content-Length) are optional and can be arbitrarly adjusted. Best, Christian [1] https://urldefense.com/v3/__https://github.com/BaseXdb/basex/blob/da1e55d0214e44c1532f121c282021db50a9aa51/basex-api/src/main/webapp/dba/common.xqm*L21-L41__;Iw!!N4vogdjhuJM!EvayIKl0SyXhq26Ctqua4mq4856Caiq9GjaVNKgILgubHKtuzRyAu4IQqUylXp6PnhaAGcBXs0AP_2w7-bJC-t0JcLVOzks$ [2] https://urldefense.com/v3/__https://docs.basex.org/wiki/Lazy_Module__;!!N4vogdjhuJM!EvayIKl0SyXhq26Ctqua4mq4856Caiq9GjaVNKgILgubHKtuzRyAu4IQqUylXp6PnhaAGcBXs0AP_2w7-bJC-t0JPvmCh9c$
OS
Omar Siam7 Jul 2022 15:55 #
Hi,
in [1] you can find some pretty generic code that I use (with search and replace for RestXQ paths) in many of my projects to serve anything in some directory related to website served using BaseX.
Another example of that code would be [2].
Best regards
Omar
[1]
https://github.com/acdh-oeaw/openapi4restxq/blob/master_basex/swagger-ui.xqm#L18-L120 [2] https://github.com/acdh-oeaw/vicav-app/blob/master/http.xqm#L9-L158
--
Mag. Ing. Omar Siam
Austrian Center for Digital Humanities and Cultural Heritage Österreichische Akademie der Wissenschaften | Austrian Academy of Sciences Stellvertretende Behindertenvertrauensperson | Deputy representative for disabled persons Bäckerstraße 13, 1010 Wien, Österreich | Vienna, Austria
T: +43 1 51581-7295
omar.siam at oeaw.ac.at | www.oeaw.ac.at/acdh
EK
Eliot Kimber7 Jul 2022 16:05 #
Omar,
Thanks for those ponters—that’s very helpful.
I was able to quickly hack the sample from the DBA code into something that works but I can see that your code is a bit more complete.
I don’t know why it was so exciting to see images on my RESTXQ-generated web pages but it was.
Cheers,
E.
_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com<https://www.servicenow.com>
LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow>
Quoted text · BaseX-Talk · 23 lines
From: BaseX-Talk <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of Omar Siam <Omar.Siam at oeaw.ac.at> Date: Thursday, July 7, 2022 at 8:55 AM To: basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] RESTXQ: Serve images that are not within the web app dir [External Email] Hi, in [1] you can find some pretty generic code that I use (with search and replace for RestXQ paths) in many of my projects to serve anything in some directory related to website served using BaseX. Another example of that code would be [2]. Best regards Omar [1] https://urldefense.com/v3/__https://github.com/acdh-oeaw/openapi4restxq/blob/master_basex/swagger-ui.xqm*L18-L120__;Iw!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBULzgb5wc$<https://urldefense.com/v3/__https:/github.com/acdh-oeaw/openapi4restxq/blob/master_basex/swagger-ui.xqm*L18-L120__;Iw!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBULzgb5wc$> [2] https://urldefense.com/v3/__https://github.com/acdh-oeaw/vicav-app/blob/master/http.xqm*L9-L158__;Iw!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBUeaN7WZQ$<https://urldefense.com/v3/__https:/github.com/acdh-oeaw/vicav-app/blob/master/http.xqm*L9-L158__;Iw!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBUeaN7WZQ$> -- Mag. Ing. Omar Siam Austrian Center for Digital Humanities and Cultural Heritage Österreichische Akademie der Wissenschaften | Austrian Academy of Sciences Stellvertretende Behindertenvertrauensperson | Deputy representative for disabled persons Bäckerstraße 13, 1010 Wien, Österreich | Vienna, Austria T: +43 1 51581-7295 omar.siam at oeaw.ac.at | https://urldefense.com/v3/__http://www.oeaw.ac.at/acdh__;!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBUJB4VrnQ$<https://urldefense.com/v3/__http:/www.oeaw.ac.at/acdh__;!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBUJB4VrnQ$>
Written for BaseX 9.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery