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.comhttps://www.servicenow.com LinkedInhttps://www.linkedin.com/company/servicenow | Twitterhttps://twitter.com/servicenow | YouTubehttps://www.youtube.com/user/servicenowinc | Facebookhttps://www.facebook.com/servicenow
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.
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
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://github.com/BaseXdb/basex/blob/da1e55d0214e44c1532f121c282021db50a9aa... [2] https://docs.basex.org/wiki/Lazy_Module
Christian,
Thanks for the pointer. I'll see if I can update the docs to more clearly cover this use case.
Cheers,
E. ________________________________ From: Christian Grün christian.gruen@gmail.com Sent: Thursday, July 7, 2022 4:09 AM To: Eliot Kimber eliot.kimber@servicenow.com Cc: basex-talk@mailman.uni-konstanz.de basex-talk@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/da1e55d021... [2] https://urldefense.com/v3/__https://docs.basex.org/wiki/Lazy_Module__;!!N4vo...
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... [2] https://github.com/acdh-oeaw/vicav-app/blob/master/http.xqm#L9-L158
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.comhttps://www.servicenow.com LinkedInhttps://www.linkedin.com/company/servicenow | Twitterhttps://twitter.com/servicenow | YouTubehttps://www.youtube.com/user/servicenowinc | Facebookhttps://www.facebook.com/servicenow
From: BaseX-Talk basex-talk-bounces@mailman.uni-konstanz.de on behalf of Omar Siam Omar.Siam@oeaw.ac.at Date: Thursday, July 7, 2022 at 8:55 AM To: basex-talk@mailman.uni-konstanz.de basex-talk@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...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/mast...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@oeaw.ac.at | https://urldefense.com/v3/__http://www.oeaw.ac.at/acdh__;!!N4vogdjhuJM!ABhSZ...https://urldefense.com/v3/__http:/www.oeaw.ac.at/acdh__;!!N4vogdjhuJM!ABhSZb1ezI_cgPgFufmVdMplTW-mgFz6hJdN-Impe8JR5Gc1G7jhmcn50jQd8XzuTyTyTeMMYVv0441MSPBUJB4VrnQ$
basex-talk@mailman.uni-konstanz.de