在xpage中从我无法访问的数据库中获取图片(acl)

Mar*_*ers 0 xpages

对于基于xpages的网页的Web用户,是否有办法能够显示(仅限读取模式)文档,该文档位于匿名无法访问acl的数据库中.如果我有访问权限,我可以获取该文档,例如: https://servername/otherdatabase.nsf/O/"+thisid+"/$FILE/"+thisdocument

我想用SessionAsSigner一定可以,但是怎么样?

其次,这个用户有没有办法从匿名无法访问的数据库中查看视图?我怎么设置它?

Tim*_*ony 9

另一种选择是使用XAgent; 例如,将beforeRenderResponse事件设置为以下内容:

var fileDb = sessionAsSigner.getDatabase((param.server || ""), param.path);
var fileDocument = fileDb.getDocumentByUNID(param.id);
var attachment = fileDocument.getAttachment(param.filename);
var inputStream = attachment.getInputStream();
var response = facesContext.getExternalContext().getResponse();
/* The following MIME type is generic, should work for all image types;
If you know what type the image will be, set a more specific MIME type */
response.setContentType("application/octet-stream");
var outputStream = response.getOutputStream();
com.acme.xsp.util.StreamUtil.copyStream(inputStream, outputStream);
inputStream.close();
outputStream.close();
attachment.recycle();
fileDocument.recycle();
facesContext.responseComplete();
Run Code Online (Sandbox Code Playgroud)

com.acme.xsp.util.StreamUtil 指的是将一个流流水线化到另一个流的Java便捷类:

public class StreamUtil {
    public static void copyStream(InputStream input, OutputStream output) throws IOException {
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,不是将图像标记直接链接到附件,而是看起来像这样:

<xp:image url="/download.xsp?server=ACME01&amp;path=images.nsf&amp;id=OU812&amp;filename=photo.jpg" />
Run Code Online (Sandbox Code Playgroud)

这种方法还可以为您提供其他选项:记录访问给定文件的次数,引用URL(如果您想实现在搜索Google时有时会看到的"无链接"图像替换),或者您想要的任何内容.

作为一个具体的例子,大约十年前,我看到一个同事实现了与Google Analytics相当的基本内部工作,甚至可以在不支持JavaScript的浏览器上工作,因为他在网站的每个页面上都使用了这种技术作为公司徽标:而不是直接链接到徽标JPG,他链接到一个抓取IP,引用,用户代理等的PHP文件,将所有元数据写入MySQL数据库,然后最终将徽标的字节流式传输到浏览器.这显然超出了你想要完成的范围,但我想你可能会觉得有趣的是,这种类型的用例现在在XPages中相当简单.