简体   繁体   English

如何使用Tapestry5从外部上下文提供文件

[英]How to serve files from outside context using Tapestry5

I'm a little stuck here. 我有点卡在这里。

I would like to store some files specific to users which can be served (as embedded objects). 我想存储一些特定于用户的文件,这些文件可以用作嵌入式对象。 These files are in a known location and the filename will be known. 这些文件位于已知位置,并且文件名也将已知。 If I store these files within the context eg ${context:/files}/abc.pdf then I have a working solution but the issue is that they are then accessible to anyone if they know the address. 如果我将这些文件存储在上下文中,例如$ {context:/ files} /abc.pdf,那么我有一个有效的解决方案,但问题是,只要知道地址,任何人都可以访问它们。

I would therefore like to store them in for example: c:/tapestry5/userfiles/ 因此,我想将它们存储在例如:c:/ tapestry5 / userfiles /

However, now I can no longer in my .tml build up a path for the embedded object. 但是,现在我无法再在.tml中为嵌入式对象建立路径。 The previous solution looks like this: 先前的解决方案如下所示:

<object width="100%" height="750px" type="application/pdf" data="${context:/exercises}${fileUrlWithinContext}" id="pdf_content">
    <p>The PDF cannot be displayed, please update your browser.</p>
</object>

So, my question is - If I have them stored outside of the context, how can I serve them so that they can be embedded on a page? 因此,我的问题是-如果将它们存储在上下文之外,我该如何提供它们以便将它们嵌入页面中?

Thanks, 谢谢,

I will answer this myself for anyone else looking. 我会为其他任何人自己回答。

The solution is to create a page which returns a StreamResponse from onActivate. 解决方案是创建一个页面,该页面从onActivate返回StreamResponse。 You can then use the link to that page as the resource, and you can put the logic in that page to go and fetch the file from wherever it is and return it as a StreamResponse. 然后,您可以使用指向该页面的链接作为资源,并且可以将逻辑放在该页面中,以从任何位置获取文件并将其作为StreamResponse返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM